![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I have a table with columns id and start_time: id | start_time -----+--------------------- 96 | 2010-11-24 09:30:00 97 | 2010-11-24 10:30:00 95 | 2010-11-25 08:00:00 I would like to write a query that will group for each *date* in the start_time column the row count... something like this: start_time | count --------------------+------- 2010-11-24 09:30:00 | 2 2010-11-25 08:00:00 | 1 Of course, there is no date column in the table, otherwise it would be too easy ![]() Any help will be appreciated! Thanks Jim with T1 (id, TS) |
#3
| |||
| |||
|
|
Hello, I have a table with columns id and start_time: id | start_time -----+--------------------- 96 | 2010-11-24 09:30:00 97 | 2010-11-24 10:30:00 95 | 2010-11-25 08:00:00 I would like to write a query that will group for each *date* in the start_time column the row count... something like this: start_time | count --------------------+------- 2010-11-24 09:30:00 | 2 2010-11-25 08:00:00 | 1 Of course, there is no date column in the table, otherwise it would be too easy ![]() Any help will be appreciated! |
#4
| |||
| |||
|
|
Hello, I have a table with columns id and start_time: id | start_time -----+--------------------- 96 | 2010-11-24 09:30:00 97 | 2010-11-24 10:30:00 95 | 2010-11-25 08:00:00 I would like to write a query that will group for each *date* in the start_time column the row count... something like this: start_time | count --------------------+------- 2010-11-24 09:30:00 | 2 2010-11-25 08:00:00 | 1 Of course, there is no date column in the table, otherwise it would be too easy ![]() Any help will be appreciated! |
#5
| |||
| |||
|
|
I don't have a psql installation at hand, so I can't verify, but you could try something like: select distinct count(*) over (partition by cast(ts as date)) ,min(TS) over (partition by cast(ts as date)) from T |
#6
| |||
| |||
|
|
select start_time, count(*) from ( select min(TS) over (partition by cast(ts as date)) as start_time from T ) as X group by start_time; |
#7
| |||
| |||
|
|
jmb (AT) nospam (DOT) com wrote on 29.11.2010 20:20: Hello, I have a table with columns id and start_time: id | start_time -----+--------------------- 96 | 2010-11-24 09:30:00 97 | 2010-11-24 10:30:00 95 | 2010-11-25 08:00:00 I would like to write a query that will group for each *date* in the start_time column the row count... something like this: start_time | count --------------------+------- 2010-11-24 09:30:00 | 2 2010-11-25 08:00:00 | 1 Of course, there is no date column in the table, otherwise it would be too easy ![]() Any help will be appreciated! If you can live with the fact that the hour is removed, this is pretty simple: SELECT cast(start_time as date), count(*) FROM your_table GROUP BY cast(start_time as date) |
#8
| |||
| |||
|
|
On 2010-11-29 22:06, Lennart Jonsson wrote: [...] select start_time, count(*) from ( select min(TS) over (partition by cast(ts as date)) as start_time from T ) as X group by start_time; without OLAP function: select start_time, count(*) from ( select cast(ts as date) as dt, min(TS) as start_time from T group by cast(ts as date) ) as X join T on dt = cast(ts as date) group by start_time |
#9
| |||
| |||
|
|
SELECT min(start_time) as start_time, count(*) FROM your_table GROUP BY cast(start_time as date) |
#10
| |||
| |||
|
|
SELECT cast(start_time as date), count(*) FROM your_table GROUP BY cast(start_time as date) |
![]() |
| Thread Tools | |
| Display Modes | |
| |