select room, max(online), time from [tablename] group by room, time
他的这个方法是对的!不明白的地方查一个MAX和GROUP BY函数-----------------------------MAX 返回表达式的最大值。 注释 MAX 忽略任何空值。对于字符列,MAX 查找排序序列的最大值。示例 下面的示例返回年度销售额最高的书。USE pubs GO SELECT MAX(ytd_sales) FROM titles GO下面是结果集:----------- 22246 (1 row(s) affected)Warning, null value eliminated from aggregate.-------------------------------------GROUP BY 将表分为组。组可包含列名、结果或计算列。
大侠们写的好像都不对呀,group by time肯定是不对的,因为没有相同的时间(精确到毫秒)select room, max(online), time from [tablename] group by room, timegroup by time的时候,要先转成字符串,然后载前10位。或者用其他方法也行,只要是精确到天就行,不能精确到秒
这样写吧, select room, max(online), time from [tablename] group by room, TO_DAYS(time);TO_DAYS函数的作用是返回所给日期的 天数,也就是精确到了天呵呵,祝大家开心:)
select room, max(online), time from [tablename] group by room, TO_DAYS(time);
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=6420
select room, max(online), time from [tablename] group by room, time
他的这个方法是对的!不明白的地方查一个MAX和GROUP BY函数-----------------------------MAX
返回表达式的最大值。
注释
MAX 忽略任何空值。对于字符列,MAX 查找排序序列的最大值。示例
下面的示例返回年度销售额最高的书。USE pubs
GO
SELECT MAX(ytd_sales)
FROM titles
GO下面是结果集:-----------
22246 (1 row(s) affected)Warning, null value eliminated from aggregate.-------------------------------------GROUP BY
将表分为组。组可包含列名、结果或计算列。
select room, max(online), time from [tablename] group by room, TO_DAYS(time);TO_DAYS函数的作用是返回所给日期的 天数,也就是精确到了天呵呵,祝大家开心:)