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 |
|
telpinaro
Starting Member
1 Post |
Posted - 2012-08-27 : 13:52:15
|
| Hello,I am trying to create a view that logs buys in a store. I need to count how many total buys an employee made per day. That part is easy... count how many times an employee code appears. Then, I need to count how many of a certain type of buy that employee made in a day. There I run in to trouble... Basically, an extremely simple version of the table looks like this:DATE EMPCODE BUYID TYPE1-1-11 1234 1001 A1-1-11 1234 1002 R1-1-11 1235 1003 AAnd I need the view to show how many total buys each employee did for each day, and how many buys of type R each employee did for each day. What would the command look like to create that type of view?Thanks! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-27 : 17:40:59
|
| [code]SELECT EMPCODE,DATE,COUNT(*) AS TotalBuys,COUNT(CASE WHEN TYPE='R' THEN 1 ELSE NULL END) AS RBuysFROM TableGROUP BY EMPCODE,DATE[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|