Soldato
- Joined
- 7 Aug 2004
- Posts
- 11,264
Hey all, from a table for example:
Im trying to list the cd_id (cd020 for example) and the number of bands involved (1, 2 or 3 for example), so id end up with the cd number and band 1, shown 14 times or something like that, how would I do that ? any hints? I know I need a group by and having clause in the command line, but for the last 3 hours it evades me!, any pointers would be great
(PS:Usually the PC 'do your own work' brigade jumps in here, its not marked work or anything like that {as term has finished!} its a work shop paper that we can do to brush up on mysql stuff and im doing that! but this one last exercise is evading me)
Iv done this:
SELECT cd_id, COUNT(*) FROM releases GROUP BY band_id;
Results in:
'cd001', 30
'cd011', 33
'cd024', 87
'cd037', 3
'cd045', 6
'cd051', 42
'cd053', 18
Which I guess is counting the cd_id and then saying how many times it appears of each band_id, but I need it to list the cd_id and number of bands involved, any clues ?
'cd001', 1
'cd002', 1
'cd003', 1
'cd004', 1
'cd005', 1
'cd006', 1
'cd007', 1
'cd008', 1
'cd009', 1
'cd010', 1
'cd011', 2
'cd012', 2
'cd013', 2
'cd014', 2
'cd015', 2
'cd016', 2
'cd017', 2
'cd018', 2
'cd019', 2
'cd020', 2
'cd021', 2
'cd024', 3
Im trying to list the cd_id (cd020 for example) and the number of bands involved (1, 2 or 3 for example), so id end up with the cd number and band 1, shown 14 times or something like that, how would I do that ? any hints? I know I need a group by and having clause in the command line, but for the last 3 hours it evades me!, any pointers would be great
(PS:Usually the PC 'do your own work' brigade jumps in here, its not marked work or anything like that {as term has finished!} its a work shop paper that we can do to brush up on mysql stuff and im doing that! but this one last exercise is evading me)
Iv done this:
SELECT cd_id, COUNT(*) FROM releases GROUP BY band_id;
Results in:
'cd001', 30
'cd011', 33
'cd024', 87
'cd037', 3
'cd045', 6
'cd051', 42
'cd053', 18
Which I guess is counting the cd_id and then saying how many times it appears of each band_id, but I need it to list the cd_id and number of bands involved, any clues ?