发新话题
打印

[转载]SQL如何不用子查询查找拥有最大值的行

[转载]SQL如何不用子查询查找拥有最大值的行

信息来源:中国最大的华文搜索站 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
曾几何时,有人对我说:装B遭雷劈。我说:去你妈的。于是,这个人又对我说:如果再说脏话,上帝会惩罚你的。我说:我操上帝。结论:彪悍的人生不需要上帝。

TOP

一定要用子查询的,select max(price)这里没有的话就没=起来的条件拉
现有极品启示:中国制造,福州出产,长170cm,重60kg。采用高级AI,零件齐全,运转极稳定,经二十多年运行,属高满意产品。现因发展需要,诚招志同道合者(仅限女性)共同研发第二代新产品,有意者请加284582241

TOP

发新话题