English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)

Find the model number of the product (PC, laptop, or printer) with the highest price.
Result set: model.

2006-09-14 23:28:04 · 7 answers · asked by Nisha N 1 in Computers & Internet Programming & Design

7 answers

select model=
case
when (price1 >= price2) and(price1 >= price3) then model1
when (price2 >= price1) and(price2 >= price3) then model2
else model3
end
from
(select top 1 price as price1 ,model as model1 from PC order by price desc)a,
(select top 1 price as price2 ,model as model2 from Laptop order by price desc)b,
(select top 1 price as price3 ,model as model3 from Printer order by price desc)c,

2006-09-15 01:44:17 · answer #1 · answered by Anonymous · 1 1

You need to run three individual queries for this:
one example is here:

select model from product where model In (select model from PC where price = (select max(price) from PC))

Replace PC with Laptop and Printer for the respective products.

2006-09-14 23:50:21 · answer #2 · answered by Indian_Male 4 · 0 0

Try this....

Select subQ.Model, max(subQ.price)
from
(
Select a.model, b.price
From Product a, PC b
Where a.model = b.model
UNION
Select a.model, b.price
From Product a, LapTop b
Where a.model = b.model
UNION
Select a.model, b.price
From Product a, Printer b
Where a.model = b.model
) subQ
Group by subQ.Model

2006-09-14 23:55:34 · answer #3 · answered by b_vinay 2 · 1 0

select model from
(
select model,price from PC where price=(select max(price)) from PC )
union
select model,price from PC where price=(select max(price)) from laptop )
union
select model,price from PC where price=(select max(price)) from printer )
)t1
where
price=(select max(price)) from t1)

i guess this will solve the problem ... bt the schema design is nt very gud ....... it can be better ....

2006-09-15 00:20:08 · answer #4 · answered by Ankur 2 · 0 0

could be between the parameters exceeded is empty. make advantageous Text5.text cloth isn't sparkling & has some fee. sometime such blunders happens once you do no longer pass a value for integer fields into sq. question. you need to use an if assertion to envision despite if Text5.text cloth is sparkling.

2016-11-07 09:10:51 · answer #5 · answered by Anonymous · 0 0

select top1 model,price from
(
select top1 model,price from PC order by price DESC
UNION
select top1 model,price from Laptop order by price DESC
UNION
select top1 model,price from Printer order by price DESC
)
order by price DESC

No need for sub-queries, no need for aggregates, you can extend it easy if u want to take from 5 more tables in future..

2006-09-15 11:07:33 · answer #6 · answered by AaRoN 2 · 0 0

I am sorry dude i had done this programming long ago and now its a big Mountain for me.

2006-09-15 02:23:51 · answer #7 · answered by A D I T Y A 2 · 0 0

fedest.com, questions and answers