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 |
|
a1234
Starting Member
1 Post |
Posted - 2008-07-21 : 01:49:53
|
| I have to write a view in sql server 2005 ona single table that looks like this:ID(int),Type(int)Status(int),Date1 (date),Date2 (date)the view must return:1. foreach type in the table - count of all the items with status = 12. foreach type in the table - the max of date1 with status = 22. foreach type in the table - the max of date1 with status = 3the tpye can be 1..100status 1..50How to write this view?Thanks!!! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-21 : 01:55:17
|
[code]select Type, sum(case when Status = 1 then 1 else 0 end) as [count of all the items with status = 1], max(case when Status = 2 then Date1 end) as [the max of date1 with status = 2], max(case when Status = 3 then Date1 end) as [the max of date1 with status = 3]from yourtablegroup by Type[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|