clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2335585 fiddles created (27423 in the last week).

CREATE TABLE artists ( id SERIAL PRIMARY KEY, name TEXT, genres jsonb );
 hidden batch(es)


INSERT INTO artists(name, genres) VALUES ('Kraftwerk', '["electronic"]'), ('Daft Punk', '["electronic", "house"]'), ('Maroon 5', '["pop", "rock"]'), ('One Republic', '["pop", "rock"]'), ('Lil Nas X', '["hip-hop", "country rap", "rap"]'), ('Post Malone', '["hip-hop", "rap", "trap"]'), ('Drake', '["hip-hop", "rap"]');
7 rows affected
 hidden batch(es)


SELECT * FROM artists;
id name genres
1 Kraftwerk ["electronic"]
2 Daft Punk ["electronic", "house"]
3 Maroon 5 ["pop", "rock"]
4 One Republic ["pop", "rock"]
5 Lil Nas X ["hip-hop", "country rap", "rap"]
6 Post Malone ["hip-hop", "rap", "trap"]
7 Drake ["hip-hop", "rap"]
 hidden batch(es)


SELECT jsonb_array_elements(artists.genres) AS genre FROM artists;
genre
"electronic"
"electronic"
"house"
"pop"
"rock"
"pop"
"rock"
"hip-hop"
"country rap"
"rap"
"hip-hop"
"rap"
"trap"
"hip-hop"
"rap"
 hidden batch(es)


SELECT jsonb_array_elements(a.genres) AS genre, COUNT(1) AS popularity FROM artists AS a GROUP BY genre ORDER BY popularity DESC;
genre popularity
"rap" 3
"hip-hop" 3
"pop" 2
"rock" 2
"electronic" 2
"house" 1
"country rap" 1
"trap" 1
 hidden batch(es)