在线等待问题!SQL语句!

kaibinsj 2002-07-10 02:05:39
如下语句
select location.province as provin,situation.reporttime as report from situation,location,mbugzone where situation.locationid=location.locationid and situation.locationid=mbugzone.locationid order by report
现在我要取situation.reporttime 的最大值,我用MAX()来取,但提示说没有group by,但我不会用group by,谁能帮我补全了?
...全文
47 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhxfzhxf1 2002-07-10
  • 打赏
  • 举报
回复
I'm Late.
kaibinsj 2002-07-10
  • 打赏
  • 举报
回复
现在我知道group by 的用法了,其实就是把非聚合元素都写上去就可以了。多谢楼上两位,最后我采用了Yang_(扬帆破浪) 的第一中方法!
kaibinsj 2002-07-10
  • 打赏
  • 举报
回复
晕,为什么都把location.province 做为group by 子项?怪我!其实这条语句我根本每写全了,因为太长了。所以可能给各位造成误会了,我把完整的贴出来
select delivery.deliveryid as deliver,situation.currentstatus as situa,location.province as provin,mbugzone.zonename as zone,situation.reporttime as report from situation,delivery,location,mbugzone where delivery.username='anda' and delivery.tripid = situation.tripid and situation.locationid=location.locationid and situation.zoneid=mbugzone.zoneid and situation.locationid=mbugzone.locationid order by report
现在是要附加取一个situation.reporttime 的最大值,按照上面两位说的现在是不行的。
Yang_ 2002-07-10
  • 打赏
  • 举报
回复
如果要取所有记录的最大值:
select max(situation.reporttime) as report from situation,location,mbugzone where situation.locationid=location.locationid and situation.locationid=mbugzone.locationid

如果要取每个location.province 的最大值:
select location.province as provin,max(situation.reporttime) as report from situation,location,mbugzone where situation.locationid=location.locationid and situation.locationid=mbugzone.locationid
group by location.province as provin

weixy 2002-07-10
  • 打赏
  • 举报
回复
select location.province as provin,max(situation.reporttime) as report from situation, location, mbugzone where situation.locationid=location.locationid and situation.locationid=mbugzone.locationid
group by location.province order by report

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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