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 |
|
Kolipaka
Starting Member
7 Posts |
Posted - 2008-10-17 : 08:02:09
|
| Hi Guys,I am new to SQL Server. When I am trying to execute the below query I am getting result as follows. but i need to get distinct results.****************************SELECT count(distinct CONVERT(VARCHAR(2), new, 3)),sum(CST.case_id)FROM CASE_STATUS_TIMESTAMP CST, OPEN_REMEDY_TICKETS ORTWHERE NEW BETWEEN '10/06/2008' AND '10/10/2008' AND (CST.CASE_ID = ORT.CASE_ID AND ORT.CATEGORY = 'Level3 Enabled Portal') GROUP BY (CONVERT(VARCHAR(2), new, 3))UNION SELECT (CONVERT(VARCHAR(2), new, 3)) as day ,count(CST.case_id) as count FROM CASE_STATUS_TIMESTAMP CST, REMEDY_TICKETS RT WHERE NEW BETWEEN '10/06/2008' AND '10/10/2008' AND (CST.CASE_ID = RT.CASE_ID AND RT.CATEGORY = 'Level3 Enabled Portal') GROUP BY (CONVERT(VARCHAR(2), new, 3))Result is :Day Count06 507 107 1708 208 1009 509 2****************But I need result like thisDay Count06 507 1808 1209 7**********************************************How can I write the query. Please help me on this.Thanks in advance.Regards,Kolipaka |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-17 : 08:06:30
|
| [code]SELECT day,SUM(Count)FROM(SELECTcount(distinct CONVERT(VARCHAR(2), new, 3)) AS day,sum(CST.case_id) AS CountFROMCASE_STATUS_TIMESTAMP CST, OPEN_REMEDY_TICKETS ORTWHERENEW BETWEEN '10/06/2008' AND '10/10/2008' AND (CST.CASE_ID = ORT.CASE_ID AND ORT.CATEGORY = 'Level3 Enabled Portal') GROUP BY (CONVERT(VARCHAR(2), new, 3))UNIONSELECT(CONVERT(VARCHAR(2), new, 3)) as day ,count(CST.case_id) as countFROMCASE_STATUS_TIMESTAMP CST, REMEDY_TICKETS RTWHERENEW BETWEEN '10/06/2008' AND '10/10/2008' AND (CST.CASE_ID = RT.CASE_ID AND RT.CATEGORY = 'Level3 Enabled Portal')GROUP BY (CONVERT(VARCHAR(2), new, 3)))tGROUP BY day[/code] |
 |
|
|
onlyforme
Starting Member
25 Posts |
Posted - 2008-10-18 : 02:18:46
|
| SELECT distinctcount(CONVERT(VARCHAR(2), new, 3)),sum(CST.case_id)FROMCASE_STATUS_TIMESTAMP CST, OPEN_REMEDY_TICKETS ORTWHERENEW BETWEEN '10/06/2008' AND '10/10/2008' AND(CST.CASE_ID = ORT.CASE_ID AND ORT.CATEGORY = 'Level3 Enabled Portal')GROUP BY(CONVERT(VARCHAR(2), new, 3))UNIONSELECT(CONVERT(VARCHAR(2), new, 3)) as day ,count(CST.case_id) as countFROMCASE_STATUS_TIMESTAMP CST, REMEDY_TICKETS RTWHERENEW BETWEEN '10/06/2008' AND '10/10/2008' AND(CST.CASE_ID = RT.CASE_ID AND RT.CATEGORY = 'Level3 Enabled Portal')GROUP BY(CONVERT(VARCHAR(2), new, 3)) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-18 : 02:20:56
|
quote: Originally posted by onlyforme SELECT distinctcount(CONVERT(VARCHAR(2), new, 3)),sum(CST.case_id)FROMCASE_STATUS_TIMESTAMP CST, OPEN_REMEDY_TICKETS ORTWHERENEW BETWEEN '10/06/2008' AND '10/10/2008' AND(CST.CASE_ID = ORT.CASE_ID AND ORT.CATEGORY = 'Level3 Enabled Portal')GROUP BY(CONVERT(VARCHAR(2), new, 3))UNIONSELECT(CONVERT(VARCHAR(2), new, 3)) as day ,count(CST.case_id) as countFROMCASE_STATUS_TIMESTAMP CST, REMEDY_TICKETS RTWHERENEW BETWEEN '10/06/2008' AND '10/10/2008' AND(CST.CASE_ID = RT.CASE_ID AND RT.CATEGORY = 'Level3 Enabled Portal')GROUP BY(CONVERT(VARCHAR(2), new, 3))
you're grouping by new and then taking count of it? this will always return count as 1 |
 |
|
|
|
|
|
|
|