SELECT *, COUNT(*) in SQLite

前端 未结 4 1196
余生分开走
余生分开走 2020-12-17 09:14

If i perform a standard query in SQLite:

SELECT * FROM my_table

I get all records in my table as expected. If i perform following query:

4条回答
  •  不知归路
    2020-12-17 09:58

    SELECT *, COUNT(*) FROM my_table is not what you want, and it's not really valid SQL, you have to group by all the columns that's not an aggregate.

    You'd want something like

    SELECT somecolumn,someothercolumn, COUNT(*) 
       FROM my_table 
    GROUP BY somecolumn,someothercolumn
    

提交回复
热议问题