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 |
|
lcpx
Yak Posting Veteran
54 Posts |
Posted - 2005-12-12 : 04:19:18
|
| We have a table, the structure as below: (I put a blank row in the middle to make it clear)Product_ID Retailer Retail_Price1001 A 1.21001 B 1.51001 C 1.41002 B 2.01002 C 2.11002 E 1.81002 F 2.01003 A 1.71003 C 1.5Basically we use the table to compare the retail price for different retailers in terms of disfferent products. My customer asked me to give a report based on above table but only shows the retail prices which contain retailer A.For example, on above table I need to give a report like below:Product_ID Retailer Retail_Price1001 A 1.21001 B 1.51001 C 1.41003 A 1.71003 C 1.5Can anybody give some ideas on how I should write a SQL to archieve this.Many thanks! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-12 : 04:28:44
|
| Select * from yourTable T where exists(Select * from yourTable where Product_id =T.Product_id and Retailer ='A')MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-12-12 : 04:32:34
|
[code]Select * from yourTable T where exists(Select * from yourTable where Retailer Product_ID =T.Retailer Product_ID and Retailer ='A')[/code]-----------------[KH]Don't live your life in one day |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-12 : 04:33:15
|
Just now I modified mine MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-12-12 : 04:34:26
|
The finger is too fast for the brain-----------------[KH]Don't live your life in one day |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-12 : 04:36:27
|
See the time 12/12/2005 04:32:34We both hit at same time MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-12-12 : 04:42:59
|
your finger is faster-----------------[KH]Don't live your life in one day |
 |
|
|
lcpx
Yak Posting Veteran
54 Posts |
Posted - 2005-12-12 : 10:36:50
|
| Many thanks for above responses, it solved the problem. Cheers! |
 |
|
|
|
|
|