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.
| Author |
Topic |
|
dineshrajan_it
Posting Yak Master
217 Posts |
Posted - 2008-02-01 : 06:02:38
|
| Helloiam new to this forum. i need a urgent helpi have table which has date columni used group by to filter how many times date has occured in that table using count(*) and i get result as 2008-02-01 00:00:00.000 42008-01-31 00:00:00.000 42008-01-10 00:00:00.000 12008-01-08 00:00:00.000 12007-12-19 00:00:00.000 42007-12-18 00:00:00.000 22007-12-15 00:00:00.000 2but what i actually need is that o/p should be displayed for total count < 10i.e2008-02-01 00:00:00.000 42008-01-31 00:00:00.000 42008-01-10 00:00:00.000 12008-01-08 00:00:00.000 1---------------------------- 10i think u can understand my point . u can see the last 3 dates are not getting displayed in this latest o/p since total count exceed 10how can i achieve itmy query isSELECT DISTINCT CAST(CONVERT(VARCHAR(15),DCOUPONDATE,101) AS DATETIME),COUNT(*)FROM COUPONSGROUP BY CAST(CONVERT(VARCHAR(15),DCOUPONDATE,101) AS DATETIME)ORDER BY CAST(CONVERT(VARCHAR(15),DCOUPONDATE,101) AS DATETIME) DESC |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-02-01 : 08:13:42
|
can you post your table DDL with sample data in insert into format ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
dineshrajan_it
Posting Yak Master
217 Posts |
Posted - 2008-02-04 : 03:04:15
|
| CREATE TABLE REQUESTTABLE(IDS INT IDENTITY(1,1) PRIMARY KEY NOT NULL,REQUESTNO VARCHAR(10),REQUESTMSG VARCHAR(1000)CREATEDDATE DATETIME)THIS IS MY TABLEAND I INSERT IT AS FOLLOWSINSERT INTO REQUESTTABLE VALUES('123','REQUEST1',GETDATE())INSERT INTO REQUESTTABLE VALUES('124','REQUEST2',GETDATE())INSERT INTO REQUESTTABLE VALUES('125','REQUEST3',GETDATE()-1)INSERT INTO REQUESTTABLE VALUES('126','REQUEST4',GETDATE()-1)INSERT INTO REQUESTTABLE VALUES('127','REQUEST5',GETDATE())INSERT INTO REQUESTTABLE VALUES('128','REQUEST6',GETDATE()-2)INSERT INTO REQUESTTABLE VALUES('129','REQUEST7',GETDATE())INSERT INTO REQUESTTABLE VALUES('127','REQUEST5',GETDATE()-1)INSERT INTO REQUESTTABLE VALUES('128','REQUEST6',GETDATE()-2)INSERT INTO REQUESTTABLE VALUES('129','REQUEST7',GETDATE())U CAN SEE THAT TODAY'DATE HAS 5 RECORDS, YESTERDAYS DATE HAS 3 AND DAY BEFORE YESTERDAY HAS 2U CAN SEE FROM MY STARTER THREAD I HAVE WRITTEN A QUERYQUERY EXECUTES AS FOLLOWS AS----------------4/2/2008 53/2/2008 32/2/2008 2BUT I NEED A RESULT AS SOMETHING LIKE THIS WHAT ARE DATES PRESENT WITHIN TOP 6 RECORDS[DISTINCT DATES] AND SO THERE COUNT AS SOEMTHING LIEK THIS4/4/2007 53/2/2008 1 [ NOT AS 3 AS PER ABOVE RESULT SINCE 5+1 EQUATES TO 6]THANK YOU |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-02-11 : 00:19:11
|
[code]SELECT DATEADD(DAY, DATEDIFF(DAY, 0, CREATEDDATE), 0), COUNT(*)FROM( SELECT TOP 6 * FROM @REQUESTTABLE ORDER BY CREATEDDATE DESC) aGROUP BY DATEADD(DAY, DATEDIFF(DAY, 0, CREATEDDATE), 0)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|