Chinaunix

标题: 如何把MAX()当条件? [打印本页]

作者: oicq63236    时间: 2008-03-01 20:59
标题: 如何把MAX()当条件?
zjlsh        jysj

1            220122
2            122333
3            153310
4            160233
5            190750

如何查找最大(zjlsh)对应的jysj,同时查询条件还得带jgbm=210024 and jyrq=20080301

[ 本帖最后由 oicq63236 于 2008-3-1 21:07 编辑 ]
作者: ivhb    时间: 2008-03-01 22:46
select
  yjsj
from your-table
where 1 = 1
and zjlsh = (
  select
    max (zjlsh)
  from your-table
)
and jgbm=210024
and jyrq=20080301
;

是这个意思么?
informix下只能这么写的。
作者: oicq63236    时间: 2008-03-02 00:09
嗯,是这个意思,我自己是这么写的
select first 1 a.cjgmc,jysj as lastsj from ggjgm a,lsflls where a.jgbm='$se
lect' and zjlsh in ( select max(zjlsh) from lsflls where jgbm='$select' and jyrq
='$TODAY')
想问一下ivhb兄,where 1 = 1是什么意思呢?在语句中有什么作用?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2