SELECT *, COUNT(*) in SQLite

前端 未结 4 1179
余生分开走
余生分开走 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:57

    If you want to count the number of records in your table, simply run:

        SELECT COUNT(*) FROM your_table;
    
    0 讨论(0)
  • 2020-12-17 09:57

    If what you want is the total number of records in the table appended to each row you can do something like

    SELECT *
      FROM my_table
      CROSS JOIN (SELECT COUNT(*) AS COUNT_OF_RECS_IN_MY_TABLE
                    FROM MY_TABLE)
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-17 10:17

    count(*) is an aggregate function. Aggregate functions need to be grouped for a meaningful results. You can read: count columns group by

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