有一个从数据库表中检索数据的小程序,请大家给一点思路,这个表中数据的特点是:(1,aa,32,23,2005-2-23);(2,aa,33,55,2005-3-24);(3,bb,24,45,2005-3-25);(4,bb,56,58,2005-4-30)等等,特点是有多个记录的某个字段相同(如:aa),其它字段不相同,检索条件是在这些有相同字段的记录中,想只检索出最后被写数据库表中的那条记录,另外只想检索出这个表中的部分字段,而不是所有的字段。
请大家给一点思路吧,我用的是DataGrid控件,结果只能检索出表中表有的数据,很郁闷!
请大家给一点思路吧,我用的是DataGrid控件,结果只能检索出表中表有的数据,很郁闷!
insert t select 'aa',32,23,'2005-2-23'
union all select 'aa',33,55,'2005-3-24'
union all select 'bb',24,45,'2005-3-25'
union all select 'bb',56,58,'2005-4-30'select col1,convert(varchar(10),max(date1),120) [date] from t group by col1
/*
result:
col1 date
---- ----------
aa 2005-03-24
bb 2005-04-30
*/
drop table t
select top 1 AutoNum,AccountID,Income,CreateDate from AccountLog group by AccountID order by CreateDate desc;错误提示为:试图执行的查询中不包含作为合计函数一部分的特定表达式‘AutoNum'。
好像是group by有语法错误,但是不知道错在什么地方,我试过即使用下面的SQL语句
select AutoNum,AccountID,Income,CreateDate from AccountLog group by AccountID ;
也会出现同样的提示!请问一下应该怎样解决?
from AccountLog a
where CreateDate=(
select max(CreateDate)
from AccountLog
where AccountID=a.AccountID
)