有如下两表table1
No A B C
201 3 x x
202 2 y y
203 3 z n
204 1 m x
..............table2
No LDate D
201 02-01-01 m
201 02-03-05 x
202 02-05-01 k
202 02-06-05 l
203 02-02-01 y
203 02-06-03 k
现在想得到如下描述的结果
1,选择table1中所有 A >=2 的记录,
2,根据1所查询的结果中的No,从table2中选择各个No中LDate最大的那一条记录
3,合并1,2 按No.够清楚吧!
No A B C
201 3 x x
202 2 y y
203 3 z n
204 1 m x
..............table2
No LDate D
201 02-01-01 m
201 02-03-05 x
202 02-05-01 k
202 02-06-05 l
203 02-02-01 y
203 02-06-03 k
现在想得到如下描述的结果
1,选择table1中所有 A >=2 的记录,
2,根据1所查询的结果中的No,从table2中选择各个No中LDate最大的那一条记录
3,合并1,2 按No.够清楚吧!
解决方案 »
- access数据库查询序号问题?急!
- 用delphi编写的WEBbroker组件做的程序该如何发布的问题
- 如下语句在sql.add()内怎么写?
- Access 中怎么设置多个字段为主键
- 高手赐教:delphi如何把文件压缩为jar格式,
- 晕…!把123456.63写入表中,存的却是123456.74,字段类型是decimal(15,2),哪错了???
- 怎样用TPrinter类打印一个类似于Excel的4行4列表格?
- 把数据库中的数据转换到Excel文件中时,数据库中的身份证号在Excel文件中显示成科学计数形式,如何才能正常显示成身份证号?
- oracle数据库&query控件
- 空当接龙游戏里不是有记分吗?这些分数是怎样记录的?
- 用Ctrl+Alt+Del关闭的程序关闭时会触发什么事件?
- 请问,在Chart或DBChart中,能使背景色变为多种颜色吗,比如使背景色变成红黄绿3中颜色?
(select table2.* from table2,(select distinct no,ldate from table2 order by ldate)as c where table2.no=c.no and table2.ldate=c.ldate)as b
where a.no=b.no
try it!
from table2 tA,
table1 tB
where tA.No = tB.No
and tB.A >= 2
and tA.lDate = (select Max(LDate) from table2 where No = tA.No)
(select table2.* from table2,(select distinct no,ldate from table2 order by ldate)as c where table2.no=c.no and table2.ldate=c.ldate)as b
where a.no=b.no
where table2.no=ta.no
where b.no=a.no
and b.ldate=select(max(ldate) from table2 where no=a.no)