求一个sql语句

yishanjushi 2004-01-16 02:10:07
请到下面的网子帮我看一下。谢谢
http://expert.csdn.net/Expert/topic/2669/2669664.xml?temp=.9270441
...全文
28 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveweb 2004-01-16
  • 打赏
  • 举报
回复
回复人: zjcxc(邹建) ( ) 信誉:216 2004-01-16 14:19:00 得分:0
select distinct * from 表 a
where createtime=(select max(createtime) from 表 where username=a.username)
order by createtime
--用distinct 是为了保证,如果createtime要相同,只取一个.如果没有这个问题,不需要distinct
--说明,如果你的表中就这两个字段,大家的方法都可以.

如果你的表中还有其他字段,并且这些字段都要显示出来,就要用我的方法
——————————————————————
这个好
say1no2 2004-01-16
  • 打赏
  • 举报
回复
如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。


select distinct xinghao,max(dd) as dtime from product group by xinghao order by dtime asc
say1no2 2004-01-16
  • 打赏
  • 举报
回复
错了,最多只能这样
select distinct xinghao,max(dd) from product group by xinghao order by xinghao desc
say1no2 2004-01-16
  • 打赏
  • 举报
回复
select distinct xinghao,max(dd) from product group by xinghao

group子句不能加order by
xieyj 2004-01-16
  • 打赏
  • 举报
回复
select distinct username,max(createtime) from tablename group by username order by createtime

28,407

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧