有一个表,我希望通过不同的条件 提取 同一编号的最后一个日期的数据
使用 select 编号,max(日期)
from 表
group by 编号不会产生问题, 但是有 where 子句时,随着where 子句条件的改变会产生同一编号的两条或者多条记录, adszhChart.CommandText := 'select 幼儿编号,Max(F_Month),max(接诊日期)
from 表 where (F_Month >= :@sM) and
(F_Month <= :@eM) and (x = 1) and (y = 0)
group by 幼儿编号 Order by 幼儿编号 adszhChart.CommandText := 'select 幼儿编号,Max(F_Month),max(接诊日期)
from 表 where (F_Month >= :@sM) and
(F_Month <= :@eM) and (x = 0) and (y = 1)
group by 幼儿编号 Order by 幼儿编号在这两个执行后会产生几个重复的 幼儿编号 记录,从而导致错误,请帮助解决而如果我使用 adszhChart.CommandText := 'select 幼儿编号,x , y ,Max(F_Month),
max(接诊日期)
from 表 where (F_Month >= :@sM) and
(F_Month <= :@eM) and (x = 0) and (y = 1)
group by 幼儿编号,x,y
Order by 幼儿编号在结果集可以看到确实存在几个 幼儿编号 重复的记录, 而实际上我需要的是每个
幼儿编号 只有一条记录谢谢
使用 select 编号,max(日期)
from 表
group by 编号不会产生问题, 但是有 where 子句时,随着where 子句条件的改变会产生同一编号的两条或者多条记录, adszhChart.CommandText := 'select 幼儿编号,Max(F_Month),max(接诊日期)
from 表 where (F_Month >= :@sM) and
(F_Month <= :@eM) and (x = 1) and (y = 0)
group by 幼儿编号 Order by 幼儿编号 adszhChart.CommandText := 'select 幼儿编号,Max(F_Month),max(接诊日期)
from 表 where (F_Month >= :@sM) and
(F_Month <= :@eM) and (x = 0) and (y = 1)
group by 幼儿编号 Order by 幼儿编号在这两个执行后会产生几个重复的 幼儿编号 记录,从而导致错误,请帮助解决而如果我使用 adszhChart.CommandText := 'select 幼儿编号,x , y ,Max(F_Month),
max(接诊日期)
from 表 where (F_Month >= :@sM) and
(F_Month <= :@eM) and (x = 0) and (y = 1)
group by 幼儿编号,x,y
Order by 幼儿编号在结果集可以看到确实存在几个 幼儿编号 重复的记录, 而实际上我需要的是每个
幼儿编号 只有一条记录谢谢
解决方案 »
- 存储过程,查询条件过滤不掉???
- 关于win7和winXP建立ODBC的问题
- 请问一个表连接的问题
- 奇怪,每天数据库变大,有内容,硬盘空间没变
- 有请邹健 : 同样的语句在 Sql server2000 与 sql server6.5中截然不同
- 给一个char类型的字段加上一个前辍出的问题
- 主表 明细表关联查询问题 十万火急。。
- SQL桌面版能否自动备份......加急
- insert into b (col1,col2,col3) select col1,col2,col3 from a where b.col4=a.col4,出错,哪错了?
- 请问我的是win10系统,安装了个mssql数据库,用的系统帐号是Test,后来我删除了,用Administrator进去,数据库就死活进不去了
- 表里面的null值搜索不到
- 怎样选 出所有不为空 的数据 行?
max(接诊日期)
from 表 where (F_Month >= :@sM) and
(F_Month <= :@eM) and (x = 0) and (y = 1)
group by 幼儿编号,x,y
Order by 幼儿编号