是否有可能使用不在GROUP BY中的ORDER BY列? [英] is it possible to use ORDER BY column not in the GROUP BY?

查看:85
本文介绍了是否有可能使用不在GROUP BY中的ORDER BY列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 选择
材料,
SUM( [金额])AS [金额],
RIGHT(CONVERT(varchar(50),[date_in],106),8)
FROM
[rec_stats]
GROUP BY
material,
RIGHT(CONVERT(varchar(50),[date_in],106),8)
ORDER BY
material,date_in

代码不会因为date_in而运行,有没有办法解决这个问题?

  order by min([date_in])解析方案



like the title said, here is my code:

SELECT
  material,
  SUM([Amount]) AS [Amount],
  RIGHT(CONVERT(varchar(50), [date_in], 106), 8)
FROM
  [rec_stats]
GROUP BY
  material,
  RIGHT(CONVERT(varchar(50), [date_in], 106), 8)
ORDER BY
  material,date_in

the code wont run because of the date_in, is there anyway to get around this?

解决方案

Apply another aggregate, so how about;

order by min([date_in])

这篇关于是否有可能使用不在GROUP BY中的ORDER BY列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆