Rohlan Posted December 17, 2010 Share Posted December 17, 2010 Hello all. I'm having a difficult time figuring out this query, I even think I've done it once before but can't seem to remember what I did. This is my data: +--+----------+ |ID | type | +--+----------+ | 1 | type_1 | | 2 | type_2 | | 3 | type_2 | | 4 | type_1 | | 5 | type_1 | +--+----------+ I simply need to get the results in this fashion: Types | Quantity type_1 | 3 type_2 | 2 Why am I not figuring this out? seems so simple.. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/221972-semi-complex-query-that-counts-number-of-occurrences-of-a-certain-value/ Share on other sites More sharing options...
trq Posted December 17, 2010 Share Posted December 17, 2010 SELECT type AS Types, COUNT(ID) AS Quantity FROM tablename GROUP BY type; Link to comment https://forums.phpfreaks.com/topic/221972-semi-complex-query-that-counts-number-of-occurrences-of-a-certain-value/#findComment-1148593 Share on other sites More sharing options...
Rohlan Posted December 17, 2010 Author Share Posted December 17, 2010 ... obviously was drawing a COMPLETE BLANK. I was forgetting the GROUP BY. Here's my query ... SELECT type, COUNT(*) AS Types FROM data_table WHERE type IS NOT NULL GROUP BY type Link to comment https://forums.phpfreaks.com/topic/221972-semi-complex-query-that-counts-number-of-occurrences-of-a-certain-value/#findComment-1148595 Share on other sites More sharing options...
Rohlan Posted December 17, 2010 Author Share Posted December 17, 2010 oh, we posted almost at the same time, hehe thank you very much for the help Link to comment https://forums.phpfreaks.com/topic/221972-semi-complex-query-that-counts-number-of-occurrences-of-a-certain-value/#findComment-1148597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.