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 |
|
drewgeezmoe
Starting Member
22 Posts |
Posted - 2007-02-20 : 00:02:30
|
| Hi i need to create this query. I have a table here named "Subject" from the database "Filteredtask". I want the output to show in this way:Subject QuantityApplication Recieved count of application recievedProcess Application count of process applicationScreen Application count of screen applicationInitial Interview count of initial interviewTechnical Exam and Interview count of technical exam and interviewI have used this code. My problem is that i put it in descending order to obtain this output, but if for example Screen application had more count it will ruin the hierarchy of the subject.SELECT subject, COUNT(subject) AS Expr1FROM dbo.FilteredTaskWHERE (subject = N'application received') OR (subject = 'process application') OR (subject = 'screen application') OR (subject = N'initial interview') OR (subject = 'profiles assessment') OR (subject = 'technical exam and interview')GROUP BY subjectORDER BY expr1 DESC__________________________________________________Your future is made by the things you are presently doing.Andrew |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-20 : 00:58:22
|
| [code]SELECT Subject, MIN(CASE Subject WHEN N'Application Received' THEN 1 WHEN 'Process Application' THEN 2 WHEN 'Acreen Application' THEN 3 WHEN N'Initial Interview' THEN 4 WHEN 'Profiles Assessment' THEN 5 WHEN 'Technical Exam and Interview' THEN 6 ELSE 0 END) AS RowOrder, COUNT(*)FROM dbo.FilteredTask.SubjectGROUP BY SubjectORDER BY 2[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
drewgeezmoe
Starting Member
22 Posts |
Posted - 2007-02-20 : 02:37:55
|
| Thanks peso.. By the way I forgot to tell you that there are other data in the table exept to the one I have specified. So if I run the syntax it shows all of the items. May you please help me output only the six items below?Thanks againRegards,Andrew__________________________________________________Your future is made by the things you are presently doing.Andrew |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-20 : 03:25:48
|
| 1) Remove the ELSE line2) Add a WHERE clauseWHERE Subject IN ('Application Received', 'Process Application', 'Acreen Application', 'Initial Interview', 'Profiles Assessment', 'Technical Exam and Interview')Peter LarssonHelsingborg, Sweden |
 |
|
|
drewgeezmoe
Starting Member
22 Posts |
Posted - 2007-02-20 : 03:52:18
|
| Thanks a lot...Regards,Andrew__________________________________________________Your future is made by the things you are presently doing.Andrew |
 |
|
|
|
|
|
|
|