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 |
jay83091
Starting Member
14 Posts |
Posted - 2014-05-08 : 02:32:14
|
Hi All,Could you please help with writing a SELECT statement for these conditions?? Thanks for your help in advance.Data SetCustomer_ID | Customer_type123 | B 123 | A124 | A125 | BRules are;- If a given Customer_ID has more than one customer types (i.e. Customer_ID = 123 above) then always use the line where customer_type = A- If there are no multiple customer types then do nothing (i.e. use the record available)The expected result set would look like;Customer_ID | Customer_type123 | A 124 | A125 | B |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-08 : 02:41:16
|
[code]SELECT Customer_ID, MIN(Customer_type)FROM yourtableGROUP BY Customer_ID[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
jay83091
Starting Member
14 Posts |
Posted - 2014-05-08 : 02:49:57
|
Thanks for your reply. are there any other approaches without using 'min'? or count? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-08 : 03:08:06
|
why can't you use MIN() ? smells like homework KH[spoiler]Time is always against us[/spoiler] |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-05-08 : 03:17:08
|
you can also use ROW_NUMBER KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|