如何在where条件下编写max函数。 [英] how to write max function in where condition.

查看:978
本文介绍了如何在where条件下编写max函数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下查询时我收到错误..



while executing below query i am getting error..

select t.d
from
(
select N_Days d , COUNT(N_Days) ds from Tbl_Setting
group by N_Days
)t
where t.ds=MAX(t.ds)







Msg 147, Level 15, State 1, Line 7
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.





我们如何编写此查询其他风格



编辑:2 /从 转发问题 - 1 [ ^ ], 问题2 [ ^ ]



How we could write this query in other style

2/ Reposted from Question - 1 [^], Question 2[^]

推荐答案

试试这个:

Try this:
select top 1 N_Days d, COUNT(N_Days) ds from Tbl_Setting group by N_Days order by ds desc;


这篇关于如何在where条件下编写max函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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