Basically, ok say my DB table has 2 columns: keyword and date.
I want to select rows but if multiple rows have the same keyword and date I want to group them and get a count of how many there are.
for example instead of getting this:
keyword: diamond, date: 20090601
keyword: diamond, date: 20090601
keyword: diamond, date: 20090602
keyword: diamond, date: 20090602
keyword: diamond, date: 20090602
I would get this:
keyword: diamond, date: 20090601, count: 2
keyword: diamond, date: 20090602, count: 3
Not sure how to do that?
Thanks!
It's called the GROUP BY
clause:
SELECT keyword, date, COUNT(1) AS count
FROM table
GROUP BY keyword, date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With