group-concat

How do I concatenate strings from a subquery into a single row in mysql?

本秂侑毒 提交于 2019-11-27 10:17:33
问题 I have three tables: table "package" ----------------------------------------------------- package_id int(10) primary key, auto-increment package_name varchar(255) price decimal(10,2) table "zones" ------------------------------------------------------ zone_id varchar(32) primary key (ex of data: A1, Z2, E3, etc) table "package_zones" ------------------------------------------------------ package_id int(10) zone_id varchar(32) What I'm trying to do is return all the information in package

GROUP_CONCAT in SQLite

浪子不回头ぞ 提交于 2019-11-27 09:14:19
I am having data like this 1 A 1 B 1 C 1 D 2 E 2 F 3 G 3 H 3 I 3 J 3 K by using this query select ABSTRACTS_ITEM._id,Name from ABSTRACTS_ITEM , ABSTRACT_AUTHOR , AUTHORS_ABSTRACT where ABSTRACTS_ITEM._id = AUTHORS_ABSTRACT.ABSTRACTSITEM_ID and ABSTRACT_AUTHOR._id = AUTHORS_ABSTRACT.ABSTRACTAUTHOR_ID Now, I want to show data like this 1 A,B,C,D 2 EF and so on..I also know it can achieve by GROUP_CONCAT function. So, I tried with this SELECT ABSTRACTS_ITEM._id, GROUP_CONCAT(ABSTRACT_AUTHOR.NAME) FROM (select ABSTRACTS_ITEM._id, Name from ABSTRACTS_ITEM , ABSTRACT_AUTHOR , AUTHORS_ABSTRACT where

SQL: Get Products from a category but also must be in another set of categories

北慕城南 提交于 2019-11-27 07:51:01
问题 I am currently stuck in a situation. The scenario is this. I have products who may be associated with multiple categories. The data structure is shown below: Products Table: product_id name 1 Lemon 2 Kiwis 3 Cheese Product to Categories Table product_id category_id 1 1 1 2 1 3 2 1 2 3 3 2 3 4 Category Table (not required in query however adding it here to help visualize what is happening) category_id name 1 Fruit 2 Yellow 3 Round 4 Dairy What I'm struggling with here is that originally I want

MySQL Group_Concat Repeating Values

强颜欢笑 提交于 2019-11-27 06:04:22
问题 I am working on an open source project called PHP-Bouncer, and I'm having issues with a MySQL Query I am writing for it. Basically we have three tables: BouncerRoles, PageInRole, and BouncerPageOverrides. BouncerRoles contains access levels, and the other two tables link back to BouncerRoles via Foreign Key and provide multiple entries of additional data. I have written the following query to attempt to pull all of the role data I need all at once: select BouncerRoles.RoleID, BouncerRoles

GROUP_CONCAT with limit

主宰稳场 提交于 2019-11-27 00:54:14
I have table with player -s in many-to-many relation with skill -s The goal is to list the players and their "top 3 skills" with a single query. fiddle create table player( id int primary key ); create table skill( id int primary key, title varchar(100) ); create table player_skills ( id int primary key, player_id int, skill_id int, value int ); Query: SELECT p.id, group_concat(s.title SEPARATOR ', ') as skills FROM player p LEFT JOIN player_skills ps ON ps.player_id = p.id LEFT JOIN skill s ON s.id = ps.skill_id WHERE ps.value > 2 -- skills limit 3 some how ... group by p.id order by s.id --

GROUP_CONCAT comma separator - MySQL

不羁岁月 提交于 2019-11-26 23:53:54
问题 I have a query where I am using GROUP_CONCAT and a custom separator as my results may contain commas: '----' This all works well, however it is still comma separated, so my output is: Result A----,Result B----,Result C---- How can I make it so the output is: Result A----Result B----Result C---- I thought this was the idea of a custom separator! Failing that, can you escape commas in your results, so I can explode in PHP by the GROUP_CONCAT commas? 回答1: Looks like you're missing the SEPARATOR

Concatenate column values for rows with the same values (of different columns)

老子叫甜甜 提交于 2019-11-26 23:38:13
问题 SQL Server 2005 I have a table which returns ID name prop value -------------------------- 1 one Prop1 a 1 one Prop1 b 1 one Prop2 c 2 two Prop1 d 2 two Prop2 e How can I run a select on it to return ID name prop value ----------------------------- 1 one Prop1 a,b 1 one Prop2 c 2 two Prop1 d 2 two Prop2 e 回答1: try this: --Concatenation with FOR XML and eleminating control/encoded character expansion "& < >" set nocount on; declare @YourTable table (RowID int, RowName varchar(5), prop varchar

MySQL - How to display row value as column name using concat and group_concat

时光怂恿深爱的人放手 提交于 2019-11-26 23:33:45
问题 Table 1: id | typeid | available| 0 | 1 | 12 | 0 | 2 | 44 | Table 2: typeid | typename | 1 | CL | 2 | ML | I have a query using concat and group_concat : select id,concat(group_concat(typename,available)) as types from table1 join table2 on table2.typeid=table1.typeid I got the result as: id | types | 0 | CL12,ML44 | But I want to display it like this: id | CL | ML | 0 | 12 | 44 | Is there any way to split the group_concat result to columns heads ? I want dynamically fetch data from table2.

JPA Criteria API group_concat usage

落爺英雄遲暮 提交于 2019-11-26 21:59:22
问题 I am currently working on a report which needs a group_concat for one of the fields. CriteriaQuery<GameDetailsDto> criteriaQuery = criteriaBuilder .createQuery(GameDetailsDto.class); Root<BetDetails> betDetails = criteriaQuery.from(BetDetails.class); Expression<String> betSelection = betDetails.get("winningOutcome"); criteriaQuery.multiselect( // other fields to select criteriaBuilder.function("group_concat", String.class, betSelection), // other fields to select ); //predicate, where clause

Trouble with GROUP_CONCAT and Longtext in MySQL

落爺英雄遲暮 提交于 2019-11-26 21:41:44
问题 The SQL... UPDATE Threads t SET t.Content = ( SELECT GROUP_CONCAT(a.Content ORDER BY a.PageID SEPARATOR '<!-- pagebreak -->') FROM MSarticlepages a WHERE a.ArticleID = t.MSthreadID GROUP BY a.ArticleID ) As you can see it takes all of an article's pages (which are each stored as longtext in separate rows) and GROUP_CONCATs them into a single longtext row. The problem is the results are only so many characters and then it gets completely truncated, losing about 90% of the contents. Does CONCAT