select top 1 部门 品种编号 结存日期 数量 from table order by 结存日期 desc; //这是取结存日期最大的一条数据。还未能实现日期最大的所有记录。 //只是抛砖引玉
不太好实现。 我所能写出的语句只能是这样: selct * from table where 部门+品种编号+convert(结存日期,char(8),112) =(select 部门+品种编号+convert(max(结存日期),char(8),112) from table order by 部门,品种编号)
to sywxy(笑钰) : 这并不是流水帐,而是对另外一个表table2不定期的结转(简单插入)。 表table2的结构只有‘部门+品种编号+数量’,”部门+品种编号“为主键。
to yangzi(笨笨): "select 部门+品种编号+convert(max(结存日期),char(8),112) from table order by 部门,品种编号" ,这个语句恐怕有问题。 注意:部门和品种编号并非是一个定值,在SQL中,它们不能与max(结存日期)做字符串连接。
sql server中 select top 1 with ties * from yourtable order by 结存日期 desc
declare @maxdate select @maxdate=max(结存日期) from table select * from table where 结存日期=@maxdate
selct * from table where 结存日期=(select max(结存日期) from table)
如果是VFP或者Access,可以: select 部门,品种编号,max(结存日期),数量 from your_table;其它数据库,我还没有发现有类似的功能。 生气呀!!!!!!!
order by 结存日期 desc;
//这是取结存日期最大的一条数据。还未能实现日期最大的所有记录。
//只是抛砖引玉
我所能写出的语句只能是这样:
selct * from table where 部门+品种编号+convert(结存日期,char(8),112) =(select 部门+品种编号+convert(max(结存日期),char(8),112) from table order by 部门,品种编号)
这并不是流水帐,而是对另外一个表table2不定期的结转(简单插入)。
表table2的结构只有‘部门+品种编号+数量’,”部门+品种编号“为主键。
"select 部门+品种编号+convert(max(结存日期),char(8),112) from table order by 部门,品种编号" ,这个语句恐怕有问题。
注意:部门和品种编号并非是一个定值,在SQL中,它们不能与max(结存日期)做字符串连接。
select top 1 with ties * from yourtable order by 结存日期 desc
select @maxdate=max(结存日期) from table
select * from table where 结存日期=@maxdate
select 部门,品种编号,max(结存日期),数量
from your_table;其它数据库,我还没有发现有类似的功能。
生气呀!!!!!!!