sqlite - Listing Number one records in a Simple SQL Database. -
i have small database 4 tables arranged follows;
table band_members columns: band_id(pk), name, dob, country, sex
table bands columns : band_id(pk), band_name
table cds columns : cd_id(pk), rdate, title, position, weeks
table releases columns : cd_id, band_id
what i'm trying display name of band , number of times they've had number 1 record. (i.e. position = '1')
this code i've tried doesn't seem working:
select band_name cds join releases on cds.cd_id = releases.cd_id join bands on releases.band_id = bands.band_id group (position='1')
you should have bandmembers_band table, have deal band members part of multiple bands - happens these days.
to answer:
select band_name, count(cds.cd_id) (select cds.cd_id, cds.position cds cds.position = 1 group cds.cd_id) join releases on cds.cd_id = releases.cd_id join bands on releases.band_id = bands.band_id group band_name having count(cds.cd_id) > 0
(pseudo - may work out of box)
Comments
Post a Comment