信息来源:中国最大的华文搜索站
www.baidu.com
SQL如何不用子查询查找拥有最大值的行?
现在有一个产品表,列如下:型号,厂家,归类(打印机,台式电脑,笔记本电脑)
还有一个台式电脑表,一个比基本表,一个打印机表,其属性为:型号,价格
如何不用子查询语句查找台式表中最大价格的型号?
如何不用子查询语句查找具有台式表,笔记本表,打印机表加在一起中最大价格的型号?
谢谢。
连接查询对一个表可以,但是对多表查最大值要别扭一些。
写写就知道了
Product(model, maker, type) type='printer' or 'pc' or 'laptop'
pc(model, price)
laptop(model, price)
printer(model, price)
我已经有了:
select model from
(select model,price from printer where price=(select maX(price) from printer)
union
select model,price from laptop where price=(select maX(price) from laptop)
union
select model,price from PC where price=(select maX(price) from PC)
)
where price IN (
select maX(price) from
(select price from printer Union
select price from laptop union
select price from pc
)
但是要不用子查询,我还是不知道怎么查。
难道是这样?
(select model,price from pc
union
select model,price from laptop
union
select model,price from printer) t1
j