Re: [sqlite] 2D query

2017-12-13 Thread Richard Hipp
On 12/13/17, Valentin Davydov  wrote:
> Given the following table:
>
> CREATE TABLE people(name,sex);
> INSERT INTO people VALUES("Alex","F");
> INSERT INTO people VALUES("Alex","M");
> INSERT INTO people VALUES("Jane","F");
> INSERT INTO people VALUES("John","M");
>
> How to construct a query which returns coalesced sex but individual names,
> such as "F: Alex, Jane. M: Alex, John."?

SELECT sex || ': ' || group_concat(name, ", ")  FROM people GROUP BY sex;

-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] 2D query

2017-12-13 Thread David Raymond
select sex, group_concat(name, ', ') from people group by sex;

(And don't forget to use single quotes for string literals)


-Original Message-
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Valentin Davydov
Sent: Wednesday, December 13, 2017 8:57 AM
To: SQLite mailing list
Subject: [sqlite] 2D query

Hi, all!

Given the following table:

CREATE TABLE people(name,sex);
INSERT INTO people VALUES("Alex","F");
INSERT INTO people VALUES("Alex","M");
INSERT INTO people VALUES("Jane","F");
INSERT INTO people VALUES("John","M");

How to construct a query which returns coalesced sex but individual names,
such as "F: Alex, Jane. M: Alex, John."?

Sincerely, 
Valentin Davydov.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] 2D query

2017-12-13 Thread Valentin Davydov
Hi, all!

Given the following table:

CREATE TABLE people(name,sex);
INSERT INTO people VALUES("Alex","F");
INSERT INTO people VALUES("Alex","M");
INSERT INTO people VALUES("Jane","F");
INSERT INTO people VALUES("John","M");

How to construct a query which returns coalesced sex but individual names,
such as "F: Alex, Jane. M: Alex, John."?

Sincerely, 
Valentin Davydov.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users