关于sql server 中查询问题(30分)

  • 主题发起人 zhengyue
  • 开始时间
Z

zhengyue

Unregistered / Unconfirmed
GUEST, unregistred user!
各位:
我有如下语句:
select max(djh),cbdj,kcsl from dspz where spbh=:mspbh

我要表达的意思是:从如下的记录中取出spbh为10001,djh最大的商品的信息也就是第四条记录;
但是在sql server 中,报错.
请问:查询语句应该怎样写;

djh cbdj kcsl spbh
1 12.5 10 10001
2 12.3 11 10001
3 15.6 15 10002
4 17.8 20 10001
5 19.2 21 10003
6 15.6 22 10002
 
恐怕你要用子查询:select * from dspz where spbh=:mspbh and djh=(select max(djh) from dspz)
 
select * from dspz a where spbh=:mspbh and djh=(select max(djh)
///
from dspz b where a.spbh=b.spbh)
// //////////////
 
select * from dspz where djh=(select max(djh) from dspz where spbh=:mspbh)
 
select (select max(djh) from dspz) as djh,cbdj,kcsl from dspz
where spbh=:mspbh
and djh=(select max(djh) from dspz)
 
同意 qianwt 的答案
 
多人接受答案了。
 
顶部