group-concat

MySQL GROUP_CONCAT with Nulls

坚强是说给别人听的谎言 提交于 2019-12-05 12:05:54
问题 Is there an option to make MySQL's Group_Concat function include nulls? Consider the following example from my source table: userId, questionId, selectionId 7, 3, NULL 7, 4, 1 7, 5, 2 When I query on the selection table with GROUP_CONCAT, I get the following: 7, 4=1,5=2 I would like to get the following: 7, 3=NULL,4=1,5=2 For reference, my query looks like this: Select userId, GROUP_CONCAT(CONCAT(questionId, '=', selectionId)) From selection Group by userId; I also tried adding an IFNULL like

order by within group concat

大憨熊 提交于 2019-12-05 11:47:39
The order by is not working in the second query. I need to order by first DNAID then DNBID First Query its ordered as: 111221 Second Query its ordered as: 112112 for more info and details about what im trying to accomplish https://stackoverflow.com/questions/5082880/database-query-group-union-find-latest mysql> select * from metarun; +----+------------+-------+-------+--------------+----------+ | ID | RunGroupID | DNAID | DNBID | CONFIGTYPEID | DateTime | +----+------------+-------+-------+--------------+----------+ | 1 | 1 | 1 | 1 | 2 | NULL | | 2 | 1 | 1 | 2 | 2 | NULL | | 3 | 1 | 2 | 1 | 2

GROUP_CONCAT with JOINLEFT in Zend Db Select

被刻印的时光 ゝ 提交于 2019-12-05 04:57:44
Assuming that I have 2 tables articles id title 1 Article 1 2 Article 2 Images id article_id image 1 1 a.png 2 1 b.png 3 2 c.png 4 2 d.png All that I want is retreive all articles with their images. For example: article_id title images 1 Article 1 a.png, b.png 2 Article 2 c.png, d.png How could I do that with Zend_Db_Select? I tried something like this but had no luck: $select = $this->getDbTable()->select()->setIntegrityCheck(false)->distinct(); $select->from(array('a'=>'articles')) ->joinLeft(array('i'=>'images'),'i.article_id=a.id',array('images'=> new Zend_Db_Expr('GROUP_CONCAT(i.image)'))

How to use sum() within a group_concat()?

为君一笑 提交于 2019-12-05 04:22:51
Question revised Really wanted a group_concat of sums... Table: shops +---------+--------+--------+ | shop_id | name | state | +---------+--------+--------+ | 0 | shop 0 | 5 | | 1 | shop 1 | 5 | | 2 | shop 2 | 5 | | 3 | shop 3 | 2 | +---------+--------+--------+ Table: items +------------+--------------+ | shop | item | quantity | +------------+--------------+ | 0 | 0 | 1 | | 0 | 1 | 2 | | 0 | 2 | 3 | | 1 | 0 | 1 | | 1 | 1 | 2 | | 1 | 2 | 3 | | 2 | 0 | 1 | | 2 | 1 | 2 | | 2 | 2 | 3 | | 3 | 0 | 1 | | 3 | 1 | 2 | | 3 | 2 | 3 | +------------+--------------+ SELECT state,SUM(i.quantity) total FROM

SQL GROUP_CONCAT split in different columns

流过昼夜 提交于 2019-12-05 00:05:14
问题 I searched a lot, but didn't find a proper solution to my problem. What do I want to do? I have 2 tables in MySQL: - Country - Currency (I join them together via CountryCurrency --> due to many to many relationship) See this for a working example: http://sqlfiddle.com/#!2/317d3/8/0 I want to link both tables together using a join, but I want to show just one row per country (some countries have multiple currencies, so that was the first problem). I found the group_concat function: SELECT

CONCAT with GROUP_CONCAT in mysql

自闭症网瘾萝莉.ら 提交于 2019-12-04 20:34:53
So I have looked everywhere for an answer to this, but so far no luck. Any help is much appreciated. I am new to mysql (transferring from a filemaker pro background). I have a database where I keep information for prospects for our business. I have a question about listing information for our users to see. The INQUIRY table holds the information for each inquiry (i.e. date inquiry came in, status of the inquiry, etc.). The PROSPECT table holds the information on each prospect (potential client) (i.e. first name, last name, age, etc.). A third table, INQUIRYNOTES , hold information on our

MySQL: Increasing GROUP_CONCAT_MAX_LEN param - any dangers?

无人久伴 提交于 2019-12-04 15:31:02
Right now, my MySQL server is using the default value of 1024 bytes for the GROUP_CONCAT_MAX_LEN, and I need to increase it. I am aware of the fact it is constrained by the MAX_ALLOWED_PACKET param, which is currently very sufficient in size. Will incraesing the GROUP_CONCAT_MAX_LEN affect anything? Does it have any consequences or dangers I should be aware of? Thanks. Aside from increasing processing time in the MySQL server, and increasing traffic (even locally), no. If you do increase it though, benchmark before and after the change. This way you can be a bit more scientific about your

group_concat was cut when running a query on table

自作多情 提交于 2019-12-04 13:39:11
I have a table that looks likes this: and this table contains 343 rows. I'm trying to run this query on it: create table newTest2 select function_name, service_name, min(concurrency), substring_index(group_concat(date order by concurrency ), ',',1) as minDate, max(concurrency), substring_index(group_concat(date order by concurrency desc), ',',1) as maxDate , avg(concurrency) from conc_intermidate group by function_name,service_name; and when I run the query it gives me the : "row 203 was cut by GROUP_CONCAT()", I don't know why it's giving me this error. Please HELP! thanks... tkyass Thanks to

MySQL - How to use subquery into IN statement by value

穿精又带淫゛_ 提交于 2019-12-04 09:58:54
The question is to get table column data and use it as a value list for IN function; For this example I created 2 tables: movies and genres Table "movies" contains 3 columns: id, name and genre. Table "genres" contains 2 columns: id and name. +- movies-+ | |- movie_id - int(11) - AUTO_INCREMENT - PRIMARY | |- movie_name - varchar(255) | |- movie_genres - varchar(255) | | +- genres-+ |- genre_id - int(11) - AUTO_INCREMENT - PRIMARY |- genre_name - varchar(255) Both tables contain some dummy data: +----------+------------+--------------+ | movie_id | movie_name | movie_genres | +----------+-----

MySQL GROUP_CONCAT multiple fields

一曲冷凌霜 提交于 2019-12-04 08:08:59
I'm probably having a no-brain moment. I want to return a series of numbers using GROUP_CONCAT from two fields in my database. I have done this so far using the following: SELECT t_id, CONCAT(GROUP_CONCAT(DISTINCT s_id),',',IFNULL(GROUP_CONCAT(DISTINCT i_id),'')) AS all_ids FROM mytable GROUP BY t_id This works fine but if i_id is NULL then of course I get an unnecessary comma. Is there a better way to do this so I don't end up with a comma at the end if i_id is NULL? You need to use CONCAT_WS to avoid extra comma for NULL values, try this: SELECT t_id, CONCAT_WS(',', GROUP_CONCAT(DISTINCT s