Ericc Posted October 2, 2020 Share Posted October 2, 2020 I have this table "plays": artist title artist_1 title_1 artist_1 title_1 artist_1 title_2 artist_2 title_1 I want to have something like this: artist title counts artist_1 title_1 2 artist_1 title_2 1 artist_2 title_1 1 I tried some querries wih SELECT DISTINCT and and GROUP BY but did not get what i wanted. Do you have any hint for me? I guess i need a sub querry. Thank you! Link to comment Share on other sites More sharing options...
Funce Posted October 13, 2020 Share Posted October 13, 2020 Hey there! Welcome to the forums! This one can be a bit mind boggling. But I did manage to get it to work. It involves using GROUP BY on both `artist` and `title`. Take a look! SELECT *, COUNT(title) FROM plays GROUP BY artist, title Link to comment Share on other sites More sharing options...
Sherin Posted October 30, 2020 Share Posted October 30, 2020 SELECT SUM(CASE WHEN column1 IS NOT NULL THEN 1 ELSE 0 END) AS column1_count ,SUM(CASE WHEN column2 IS NOT NULL THEN 1 ELSE 0 END) AS column2_count ,SUM(CASE WHEN column3 IS NOT NULL THEN 1 ELSE 0 END) AS column3_count FROM table Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now