Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with select statment in oracle

Author  Topic 

g_r_a_robinson
Starting Member

45 Posts

Posted - 2004-03-25 : 19:19:19
I need to return the following from my db, eg

Date User (Count)

12/01/04 23
13/01/04 17
14/01/04 12
15/01/04 9
16/01/04 32

Basically I just need to return a list count of all users that cancelled orders with a specified date range on the given dates.

I'm just not sure how to do it.

Any help would be most appreciated

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-03-25 : 19:21:07
Got a table layout and sample data? What you've posted is the expected result set but we need table information and what the data looks like?

Tara
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2004-03-25 : 19:57:50
Without knowing the layout of your tables, and with inputting my own column/table names.

SELECT   TRUNC(cancel_date) as "Cancel Date", 
COUNT(TRUNC(cancel_date)) as "User Count"
FROM table_name
WHERE cancel_date BETWEEN '01-JAN-2004' and sysdate
GROUP BY TRUNC(cancel_date)
ORDER By TRUNC(cancel_date)


You may or may not have to use the TRUNC function here. TRUNC strips off the time component so you can make date comparisons just on the day, not down to the second. If your cancel_date is that granular (down to minutes and seconds for example) and you don't use TRUNC, the GROUP BY operation will fail to roll your data up to the day.


-ec
Go to Top of Page
   

- Advertisement -