group-concat

Simulate GROUP_CONCAT function in HSQLDB versions < 2?

微笑、不失礼 提交于 2019-12-13 02:50:08
问题 LO/OOO Base doesn't come with an HSQLDB version > 2 which means there is no GROUP_CONCAT function. Is there a way to simulate this function in HSQLDB versions < 2? Here's an example for the columns name and value before the function is applied: TIM | 51 TIM | 53 TIM | 55 JOHN | 103 JOHN | 104 I would like to use (H)SQL code in Base that returns something similar to the result of GROUP_CONCAT: TIM | 51, 53, 55 JOHN | 103, 104 (A similar question has been asked for other DBMS but the answers

MySQL group_concat() ordering by case statement values

a 夏天 提交于 2019-12-13 02:34:51
问题 In a MySQL group_concat() clause, I'm trying to order the resulting values of a case statement. The following query configuration properly orders things.name but does not order the 'Non-US' or 'Unknown' values within the same context. SELECT things.id ,group_concat(DISTINCT CASE WHEN things.name <> 'United States' THEN 'Non-US' WHEN things.name IS NULL THEN 'Unknown' ELSE things.name END ORDER BY name SEPARATOR ', ') FROM things GROUP BY things.id I want to do something like this, but it's

MySQL: condition on result of GROUP_CONCAT?

懵懂的女人 提交于 2019-12-13 01:50:45
问题 I have an SQL setup akin to the following: ARTICLES id (PK) name TAGS id (PK) tag ...and a third table logging associations between the two, since there can be multiple tags to each article: ARTICLE_TAG_ASSOCS id (PK) article_id (FK) tag_id (FK) Question: how to find articles that have a particular tag? The best I could come up with was this: SELECT name, GROUP_CONCAT(CASE WHEN tag = 'some-tag' THEN tag ELSE NULL END) AS tags FROM articles, tags, article_tag_assocs WHERE articles.id = article

How to return ordered data from multiple records into one record in MySQL?

自古美人都是妖i 提交于 2019-12-12 23:00:11
问题 I have a MySQL database with a table of survey responses with three important fields (renamed for clarity): SURVEY_TAKER_ID, QUESTION_NUMBER, and RESPONSE. Assuming a 3-question survey as an example, it would look something like this: SURVEY_TAKER_ID | QUESTION_NUMBER | RESPONSE ---------------------------------------- 101 1 Apple 102 1 Orange 103 1 Banana 101 2 Morning 102 2 Evening 103 2 Afternoon 101 3 Red 102 3 Blue 103 3 Yellow I would like to create a SELECT query that outputs each

Weird result for GROUP_CONCAT on subquery

对着背影说爱祢 提交于 2019-12-12 17:23:41
问题 I am having a weird behavior when using GROUP_CONCAT on subquery. Here is my query : SELECT name, GROUP_CONCAT(DISTINCT (id) SEPARATOR "-") AS id FROM ( (SELECT "APN" AS name, GROUP_CONCAT(DISTINCT (site.id) SEPARATOR "-") AS id FROM site WHERE id IN (138, 147, 8918, 8916, 9033, 9240, 97, 9038, 8886, 9036, 9067, 146, 37, 9127, 52, 9031, 23, 8635, 8665, 46, 39, 18, 33, 9035, 137, 9051, 8766, 25, 20, 9160, 133, 8636, 9021, 8655, 21, 42, 8757, 22, 9017, 77, 9037, 44, 49, 9323, 55, 74, 150, 8, 67

GROUP_CONCAT and Longtext

谁说我不能喝 提交于 2019-12-12 13:26:46
问题 I need to combine two text fields in the MySQL Database table into One, So I have used the Following SQL script to do it. Table: tbl_newsitems Combine: Need to combine the text in the 'ni_text' with the same 'news_id' Table Layout: Code used to combine the text: SELECT news_id , GROUP_CONCAT( ni_text SEPARATOR ' ') FROM tbl_newsitems GROUP BY news_id ; But it won't display the full (Complete) text in the result section. The CONCAT field is trimmed and missing some text. The default Data type

CONCAT with GROUP_CONCAT in mysql

佐手、 提交于 2019-12-12 09:27:59
问题 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

MySQL: combining multiple values after a join into one result column

橙三吉。 提交于 2019-12-12 08:24:38
问题 I have a database with a table for publications, each of which can have multiple authors that are stored in a different table. I'd like to query the database into giving me a list of publication titles in one column, and the combined authors for that publication in the second. SELECT p.`id`, p.`title`, a.`fullname` from `publications` p LEFT JOIN `authors` a on a.`publication_id` = p.`id`; This of course gives me multiple times the publication title for as many authors. id title fullname -- -

GROUP_CONCAT return NULL if any value is NULL

落爺英雄遲暮 提交于 2019-12-12 08:06:08
问题 How can I make GROUPT_CONCAT return NULL if any column is NULL ? Here is a test table: CREATE TABLE gc ( a INT(11) NOT NULL, b VARCHAR(1) DEFAULT NULL ); INSERT INTO gc (a, b) VALUES (1, 'a'), (1, 'b'), (2, 'c'), (2, NULL), (3, 'e'); And my query: SELECT a, GROUP_CONCAT(b) FROM gc GROUP BY a; This is what I get: a | GROUP_CONCAT(b) --+---------------- 1 | a,b 2 | c 3 | e This is what I want: a | GROUP_CONCAT(b) --+---------------- 1 | a,b 2 | NULL 3 | e 回答1: In an IF expression check if any

Pivot Table Omitting Rows that Have Null values

ε祈祈猫儿з 提交于 2019-12-12 04:53:09
问题 I am solving a problem very similar to this only in my case, I am not summing any values. I have been able to write a select that works using solution from this page SELECT id, GROUP_CONCAT(if(colID = 1, value, NULL)) AS 'First Name', GROUP_CONCAT(if(colID = 2, value, NULL)) AS 'Last Name', GROUP_CONCAT(if(colID = 3, value, NULL)) AS 'Job Title' FROM tbl GROUP BY id; However, I want to omit rows that have the value to be null 回答1: I assume you want to drop the result row if any of the source