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 |
|
mahimam_2004
Starting Member
40 Posts |
Posted - 2006-12-21 : 15:24:25
|
| Hi, I have a query,SELECT Count(*) as Casecount, exrank AS NoOfSubstances From cacase c INNER JOIN paPatient pp ON pp.caCaseID=c.caCaseID INNER JOIN exExposure ee ON ee.caCaseID=c.caCaseID INNER JOIN exExposureSubstance es ON c.caCaseID=es.caCaseIDGroup By exRankWhich is returning results like the following format:No.of substances ,CaseCount---------------- -----------1 ,32 ,693 ,98.. ,..11 ,56.. ,..20 ,788Now I need to get the result like this:No.Of substances , CaseCount--------------- --------------1 ,32 ,693 ,98.. ,..8 ,56>=9 ,123Like that >=9 CaseCount have to show the Sum of CaseCounts for which No.of substances>=9.How to acheve this.Thanks in advance |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-21 : 15:42:16
|
| [code]SELECT case when exrank < 9 THEN CAST(exrank as varchar) else '>= 9' end AS NoOfSubstances, Count(*) as CasecountFrom cacase cINNER JOIN paPatient pp ON pp.caCaseID=c.caCaseIDINNER JOIN exExposure ee ON ee.caCaseID=c.caCaseIDINNER JOIN exExposureSubstance es ON c.caCaseID=es.caCaseIDGroup By case when exrank < 9 THEN CAST(exrank as varchar) else '>= 9' end[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
mahimam_2004
Starting Member
40 Posts |
Posted - 2006-12-21 : 16:12:28
|
| Hi,Thank you very much.It working.Now how to sort i.e Order ByOrder by .Display >=9 lastWhen i sort Order by Noofsubstance >=9 is displaying firstWithout Order By also It is displaying FirstHow to show >=9 as last column in the result.Thanks in advance |
 |
|
|
mahimam_2004
Starting Member
40 Posts |
Posted - 2006-12-21 : 16:25:26
|
| Hi,I solved it. |
 |
|
|
|
|
|
|
|