SQLite count, group and order by count

前端 未结 1 1367
慢半拍i
慢半拍i 2020-12-29 18:38

I have a table that looks like this:

FOO  BAR  BAZ
----+----+----
foo1 bar1 baz1
foo2 bar3 baz2
foo3 bar1 baz3
foo4 bar1 baz4
foo5 bar3 baz5
foo6 bar1 baz6
f         


        
相关标签:
1条回答
  • 2020-12-29 19:18
    SELECT foo, count(bar) FROM mytable GROUP BY bar ORDER BY count(bar) DESC;
    

    The group by statement tells aggregate functions to group the result set by a column. In this case "group by bar" says count the number of fields in the bar column, grouped by the different "types" of bar.

    A better explanation is here: http://www.w3schools.com/sql/sql_groupby.asp

    0 讨论(0)
提交回复
热议问题