1

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?

1 Answer 1

10
SELECT  TRUNC(date) AS CreatedDate, COUNT(*) AS DateCount
FROM    mytable
GROUP BY
        TRUNC(date)
ORDER BY
        CreatedDate
Sign up to request clarification or add additional context in comments.

6 Comments

Doing this in PL/SQL requires creating a cursor from your query. Not very difficult at all.
+1: you beat me to it, but i would have called it this_table.
I don't understand how count(*) would correspond to the count of those entries that correspond to each distinct date.
@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.
Also, what if i want to display the date column as "CreatedDate" and Sort by that column ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.