SQL求记录总数并列出所有字段。
表table1如下:
id uid loginIp loginTime
1 5 127.0.0.1 2007-3-22
2 5 127.0.0.1 2007-3-24
3 3 127.0.0.1 2007-3-26
4 5 127.0.0.1 2007-3-27
5 3 127.0.0.1 2007-3-28
求出所有uid=5的记录总数,并列出最新一条记录所所有字段值,如下:
记录总数 uid loginIp loginTime
3 5 127.0.0.1 2007-3-27
可以用一条sql语句实现吗?怎样写?
在ASP中我是用recordcout来做的,
set rs=Server.CreateObject( "Adodb.RecordSet ")
rs.open "select * from table1 where uid=5 order by loginTime desc ",conn,1,1
Rscount=rs.recordcount
我想这样做:
set rs=conn.execute(sql)
不知道这条语句怎样写才能得到想要的结果(Access,MSSQL下匀通过),请各位帮帮忙。
[解决办法]
select top 1 *, (select count(*) from table1 where uid=5) as countnum from table1 where uid=5 order by loginTime desc