I have a table Company
, and I want to group the entries by Male
and Female
.
And I want their names listed in a column.
The result should like as shown here:
+--------+----------+---------------------+ | Count | Gender | Name | +--------+----------+---------------------+ | 5 | M | Sandy, Loli , Deays.| | 3 | F | Any , Any....... | +--------+----------+---------------------+
I got the count of the male and female, but I also need the names in a single column
Advertisement
Answer
Try This but please keep in mind that STRING_AGG
is not available on every DBMS system
select Gender, count(*) Count, String_agg(name, ',') from t group by Gender