| Author |
Topic |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 07:06:28
|
| select f.mobid, f.merchant, x.minprice, x.maxpricefrom (select mobid, min(price) as minprice, max(price) as maxpricefrom tbl_merchant group by mobid) as x inner join tbl_merchant as f on f.mobid = x.mobid and f.price = x.minprice order by mobidThis query selects min & max price i need that merchant name also |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 07:13:24
|
| Please help me ....... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-24 : 07:23:32
|
| your query looks fine. whats the problem then?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 07:26:36
|
| this query selects min & max price values, merchant names from my table.... i need the name of that merchant also ...Who is min & whose max holder |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 07:34:45
|
| My table contains merchant name in one field and price in another field ...I already separated min & max price values from price field now i want the name of the merchant |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-24 : 07:37:57
|
ok here you goselect mobid, merchant,pricefrom(select row_number() over (order by price) as seq,row_number() over (order by price desc) as bseq,mobid, merchant,pricefrom tbl_merchant)twhere seq=1or bseq=1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 07:42:02
|
| I need my result as mobid|min_merchant|min_price|Max_merchant|max_price |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 07:43:45
|
| Your query just returns mobid|merchant|price |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 07:44:32
|
| To get my o/p how to modify my query |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-24 : 07:50:05
|
do you mean you've multiple merchants per mobid? then it should beselect mobid, max(case when seq=1 then merchant else null end) as minmerchant,max(case when seq=1 then price else null end) as minprice,max(case when bseq=1 then merchant else null end) as maxmerchant,max(case when bseq=1 then price else null end) as maxpricefrom(select row_number() over (partition by mobid order by price) as seq,row_number() over (partition by mobid order by price desc) as bseq,mobid, merchant,pricefrom tbl_merchant)twhere seq=1or bseq=1group by mobid ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 07:56:49
|
| Thanks a lot ..Its working... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-25 : 09:13:46
|
quote: Originally posted by jafrywilson Thanks a lot ..Its working...
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|