MySQL: counting grouped items?

Basically, it's good that my DB table has 2 columns: keyword and date .

I want to select rows, but if several rows have the same keyword and date, I want to group them and get the number of their number.

for example, instead:

keyword: diamond, date: 20090601 keyword: diamond, date: 20090601 keyword: diamond, date: 20090602 keyword: diamond, date: 20090602 keyword: diamond, date: 20090602 

I would get the following:

 keyword: diamond, date: 20090601, count: 2 keyword: diamond, date: 20090602, count: 3 

Not sure how to do this?

Thanks!

+4
source share
1 answer

He called GROUP BY :

 SELECT keyword, date, COUNT(1) AS count FROM table GROUP BY keyword, date 
+10
source

Source: https://habr.com/ru/post/1285766/


All Articles