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 |
|
FernandoLorival
Starting Member
19 Posts |
Posted - 2011-02-19 : 19:38:04
|
| Hi All,I have a movies table that contains MovieID, MovieName, Status.Status tells me if the movie is IN or OUT.I want to build a query that gives me 3 columns: MovieID, IN, OUTMy table looks like this:MovieID -- MovieName -- Status1 -- Bla -- IN2 -- Bli -- IN1 -- Bla -- OUT1 -- Bla -- OUT......Something like this:MovieID -- IN -- OUT1 -- 6 -- 42 -- 7 -- 9It looks simple but i cant get around the fact that i need 2 WHERE cluases in the same query!!Thank you all! |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-02-19 : 21:48:58
|
| SELECT MovieID, SUM(CASE WHEN Status='IN' THEN 1 END) IN,SUM(CASE WHEN Status='OUT' THEN 1 END) OUTFROM MoviesGROUP BY MovieID |
 |
|
|
RobertKaucher
Posting Yak Master
169 Posts |
Posted - 2011-02-19 : 22:10:33
|
| robvolk's query was much better - simpler! I retract mine. ;-) |
 |
|
|
FernandoLorival
Starting Member
19 Posts |
Posted - 2011-02-19 : 22:17:20
|
| That works!Thank you soo much!!! |
 |
|
|
|
|
|