tags:

views:

40

answers:

1
+1  Q: 

Oracle Query Help

I have this table

  ID          Date
  1   08/10/2009 11:20:00
  2   08/10/2009 12:06:06
  3   08/11/2009 13:03:10
  4   08/11/2009 01:20:00
  5   08/11/2009 15:41:23
  6   08/12/2009 14:22:20

I want to return:

Date          Count
08/10/2009     2
08/11/2009     3
08/12/2009     1

in PL/SQL. Any ideas?

+10  A: 
SELECT  TRUNC(date) AS CreatedDate, COUNT(*) AS DateCount
FROM    mytable
GROUP BY
        TRUNC(date)
ORDER BY
        CreatedDate
Quassnoi
Doing this in PL/SQL requires creating a cursor from your query. Not very difficult at all.
Thomas Jones-Low
+1: you beat me to it, but i would have called it `this_table`.
akf
I don't understand how count(*) would correspond to the count of those entries that correspond to each distinct date.
Saobi
`@Saobi`: `TRUNC(date)` truncates the dates, leaving only the date portions. `GROUP BY TRUNC(date)` makes `COUNT(*)`'s for each group that shares the truncated values of the dates.
Quassnoi
Also, what if i want to display the date column as "CreatedDate" and Sort by that column ?
Saobi
`@akf`: that's why I use `mytable`. It's shorter.
Quassnoi
`@Saobi`: see the post update.
Quassnoi