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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.