Author |
Topic |
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 04:14:52
|
select t1.*,t2.Product_Name from(select mobid,max(case when seq=1 then merchant else null end) as min_merchant,max(case when seq=1 then price else null end) as min_price,max(case when bseq=1 then merchant else null end) as max_merchant,max(case when bseq=1 then price else null end) as max_pricefrom(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=1 or bseq=1) and mobid in(select MOBID from tbl_product where Client_Name='wilson')group by mobid) as t1 INNER JOIN tbl_product as t2 on t2.mobid=t1.mobidIn the above query i need to add my_Price field wheremy_price is where my name matches for that productthanks in advance .... |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-25 : 05:06:50
|
From which table does my_price derive?At least you can learn to prefix your column names, so that we don't have to guess from where the columns derive from.SELECT t.MobID, MAX(CASE WHEN t.seq = 1 THEN t.Merchant ELSE NULL END) AS min_merchant, MAX(CASE WHEN t.seq = 1 THEN t.Price ELSE NULL END) AS min_price, MAX(CASE WHEN t.bseq = 1 THEN t.Merchant ELSE NULL END) AS max_merchant, MAX(CASE WHEN t.bseq = 1 THEN t.Price ELSE NULL END) AS max_priceFROM ( SELECT ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price DESC) AS bseq, ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price) AS seq, MobID, Merchant, Price FROM tbl_Merchant ) AS tWHERE 1 IN (t.seq, t.bseq) AND t.MobID IN (SELECT p.MobID FROM tbl_Product AS p WHERE p.Client_Name = 'Wilson')GROUP BY t.MobID N 56°04'39.26"E 12°55'05.63" |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 05:17:22
|
By mobid i joined two tables, tables product,merchant .. merchant table contains merchant name and price columns From that i retrieved max_price and min_price ,merchant_names ...Now i want to show my price in the same table..My price is nothing but where my name matches |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-25 : 05:19:43
|
And column "my_price" is stored in tbl_Product table? N 56°04'39.26"E 12°55'05.63" |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 05:20:02
|
for examplewilson 100jafry 200marlen 150min_price merchant wilsonmax_price merchant jafryif marlen is user then my_price would be 150 |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 05:23:14
|
can u able to get my point |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-25 : 05:32:20
|
quote: Originally posted by jafrywilson can u able to get my point
Barely. Remember, all we know about your problem is what you write. We don't have prior knowledge of your application, nor do we have access to it.Is this what you want?SELECT t.MobID, z.my_Price AS MyPrice, MAX(CASE WHEN t.seq = 1 THEN t.Merchant ELSE NULL END) AS min_merchant, MAX(CASE WHEN t.seq = 1 THEN t.Price ELSE NULL END) AS min_price, MAX(CASE WHEN t.bseq = 1 THEN t.Merchant ELSE NULL END) AS max_merchant, MAX(CASE WHEN t.bseq = 1 THEN t.Price ELSE NULL END) AS max_priceFROM ( SELECT ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price DESC) AS bseq, ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price) AS seq, MobID, Merchant, Price FROM tbl_Merchant ) AS tINNER JOIN ( SELECT MobID, my_Price FROM tbl_Product WHERE Client_Name = 'Wilson' ) AS z ON z.MobID = t.MobIDWHERE 1 IN (t.seq, t.bseq)GROUP BY t.MobID, z.my_Price N 56°04'39.26"E 12°55'05.63" |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 05:36:52
|
Sorry...forgive me..It selects from table_productMy need is to select from table_merchant |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 05:39:40
|
simple example to my tasktable 1id mobid product description user name 1 aa1 xxxx xxxxxx qqq 1112 aa1 xxxx xxxxxx www 1113 aa1 xxxx xxxxxx eee 1114 aa2 yyyy yyyyyy rrr 2225 aa2 yyyy yyyyy qqq 2226 aa3 zzzzz zzzzzz qqq 333table 2id mobid merchant price 1 aa1 wilson 102 aa1 jafry 113 aa1 abcd 84 aa2 wilson 55 aa2 jafry 4i need my output like this( my name is wilson)...name | description | my_price | lowprice_merchant | low_price | maxprice_merchant | max_price 111 xxxxx 10 abcd 8 jafry 11 |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 05:42:23
|
table 1id mobid product description user name1 aa1 xxxx xxxxxx qqq 1112 aa1 xxxx xxxxxx www 1113 aa1 xxxx xxxxxx eee 1114 aa2 yyyy yyyyyy rrr 2225 aa2 yyyy yyyyy qqq 2226 aa3 zzzzz zzzzzz qqq 333table 2id mobid merchant price1 aa1 wilson 102 aa1 jafry 113 aa1 abcd 84 aa2 wilson 55 aa2 jafry 4i need my output like this( my name is wilson)...name | description | my_price | lowprice_merchant | low_price | maxprice_merchant | max_price111 xxxxx 10 abcd 8 jafry 11 |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-25 : 05:58:35
|
See my suggestion dated 08/25/2010 : 05:32:20.Is that close to what you want? N 56°04'39.26"E 12°55'05.63" |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 06:07:09
|
No.. your query gives mobid,min_price,min_merchant,max_price,max_mrechantmy_price is selected in table_product .. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-25 : 06:08:59
|
Are you really, REALLY, really sure you ran this piece of code?SELECT t.MobID, z.my_Price AS MyPrice, MAX(CASE WHEN t.seq = 1 THEN t.Merchant ELSE NULL END) AS min_merchant, MAX(CASE WHEN t.seq = 1 THEN t.Price ELSE NULL END) AS min_price, MAX(CASE WHEN t.bseq = 1 THEN t.Merchant ELSE NULL END) AS max_merchant, MAX(CASE WHEN t.bseq = 1 THEN t.Price ELSE NULL END) AS max_priceFROM ( SELECT ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price DESC) AS bseq, ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price) AS seq, MobID, Merchant, Price FROM tbl_Merchant ) AS tINNER JOIN ( SELECT MobID, my_Price FROM tbl_Product WHERE Client_Name = 'Wilson' ) AS z ON z.MobID = t.MobIDWHERE 1 IN (t.seq, t.bseq)GROUP BY t.MobID, z.my_Price N 56°04'39.26"E 12°55'05.63" |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 06:12:16
|
did u see how i am selecting min,max price in a single field price... likewise i need to select merchant name from a single field named as merchant in merchant table ... now i want to show that if i am entering as wilson in the page then disply my price along with min,max price |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 06:16:46
|
ya sure .. i ran this querymobid my_price min_merchant min_price max_merchant max_price93667 NULL TEPTRONICS 74.99 Amazon.com Marketplace 89.9593668 NULL Amazon.com 9.96 TEPTRONICS 44.99i got this output... |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 06:51:31
|
it is very confusing please help me |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-08-25 : 07:01:16
|
If you want only one merchant name, trySELECT t.MobID, z.my_Price AS MyPrice, t.Merchant , MAX(CASE WHEN t.seq = 1 THEN t.Price ELSE NULL END) AS min_price, MAX(CASE WHEN t.bseq = 1 THEN t.Price ELSE NULL END) AS max_priceFROM ( SELECT ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price DESC) AS bseq, ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price) AS seq, MobID, Merchant, Price FROM tbl_Merchant ) AS tINNER JOIN ( SELECT MobID, my_Price FROM tbl_Product WHERE Client_Name = 'Wilson' ) AS z ON z.MobID = t.MobIDWHERE 1 IN (t.seq, t.bseq)GROUP BY t.MobID, t.merchant, z.my_Price MadhivananFailing to plan is Planning to fail |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 07:04:03
|
NO This is not my requirement |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 07:05:15
|
yesterday you send me this codeselect t1.*,t2.Product_Name from(select mobid,max(case when seq=1 then merchant else null end) as min_merchant,max(case when seq=1 then price else null end) as min_price,max(case when bseq=1 then merchant else null end) as max_merchant,max(case when bseq=1 then price else null end) as max_pricefrom(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=1 or bseq=1) and mobid group by mobid) as t1 INNER JOIN tbl_product as t2 on t2.mobid=t1.mobid |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 07:08:05
|
(select MOBID from tbl_product where Client_Name='wilson')i inserted this code for my need ..if i entered with my name i need to show my price as i described earlier .. |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 07:21:02
|
my required output mus be in this formatname | description | my_price | minprice_merchant | min_price | maxprice_merchant | max_price |
 |
|
Next Page
|