FinalJon
FinalJon

Reputation: 385

Tallying up similar SQL rows

I have a table that is described with two columns: an index, and a date.

How would I run a query so that: for each date, it tallies how many entries are for that date, and does it for every date that appears?

I know I can COUNT for a specific date, but I'm lost as to how to do this for each date.

(I'm using SQLite, but a description for any SQL language would be very helpful). Thanks!

Upvotes: 0

Views: 122

Answers (3)

Mike
Mike

Reputation: 3

If a field is not in the "group by" list then you cannot include it unless you are performing some aggregate function on it (count, sum, etc.).

select "date_field", count(*)  from "table" group by "date_field";

Also, SQLite does not have to use backticks (`) like MySQL, you can use double quotes.

Upvotes: -1

Nikhil
Nikhil

Reputation: 1

select index, date, COUNT(*) from tbl
group by index, date

check this.... let me know if it works.....

Upvotes: 0

juergen d
juergen d

Reputation: 204756

select `date`, count(*) 
from your_table
group by `date`

Upvotes: 2

Related Questions