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 |
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2014-04-03 : 04:15:23
|
hallopleas help me.I have this table.TabSalenumcustomer.......salesman....branch1.................John.........1001.................John.........2001.................Georg........5002.................Smith........9002.................Smith........5002.................Alan.........7003..................Xena........9003..................Xena........6003..................Xena........200I need this select :numcustomer.....salesman1..............John1..............Georg2...............Smith2...............AlanI need to select numcustomer where are 2 salesmans.thanks boys |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-04-03 : 04:51:51
|
[code];with TabSaleAS (select 1 as numcustomer,'John' as salesman,100 as branch union all select 1,'John',200 union all select 1,'Georg',500 union all select 2,'Smith',900 union all select 2,'Smith',500 union all select 2,'Alan',700 union all select 3,'Xena',900 union all select 3,'Xena',600 union all select 3,'Xena',200)select numCustomer ,salesmanfrom TabSalewhere numCustomer in (select numCustomer from ( select numCustomer ,rank() Over(Partition by numCustomer Order by salesman) as countCustomer from TabSale)A where A.countCustomer>1)Group by numCustomer, SalesMan[/code]sabinWeb MCP |
|
|
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2014-04-03 : 06:53:03
|
thanks thanks stepson |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-04-03 : 07:01:09
|
You are welcome!sabinWeb MCP |
|
|
|
|
|
|
|