Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张像这样的桌子:
id_cat id_city 1 33 1 33 1 33 2 44 2 33 2 55
我想获得如下结果:
id_cat id_city cat_count 1 33 3 2 44 1 2 33 1 2 55 1
我怎样才能建立我的查询?谢谢!
使用COUNT()which 是一个聚合函数和一个GROUP BY子句。
COUNT()
GROUP BY
SELECT id_cat, id_city, COUNT(*) cat_Count FROM tableName GROUP BY id_cat, id_city