having 子句在 sql 中不起作用
having clause is not working in sql
我不明白这句话有什么问题。
Select customername,LEN(address)
FROM customers group by customername having LEN(address) = 13;
这是错误信息
没有分组或聚合的 HAVING 子句 (LEN(address)=13)。
尝试使用 where 子句
Select customername,LEN(address) as lenadressnamecolumn
FROM customers where LEN(address) = 13;
address
和 LEN(address)
都不在 GROUP BY
中。因此,您需要添加它们或将表达式包装在聚合函数中:
SELECT customername, MAX(LEN(address))
FROM customers
GROUP BY customername
HAVING MAX(LEN(address)) = 13;
或者如果您只需要长度为 13 的客户,也许根本不需要聚合:
SELECT customername
FROM customers
WHERE LEN(address) = 13;
我不明白这句话有什么问题。
Select customername,LEN(address)
FROM customers group by customername having LEN(address) = 13;
这是错误信息 没有分组或聚合的 HAVING 子句 (LEN(address)=13)。
尝试使用 where 子句
Select customername,LEN(address) as lenadressnamecolumn
FROM customers where LEN(address) = 13;
address
和 LEN(address)
都不在 GROUP BY
中。因此,您需要添加它们或将表达式包装在聚合函数中:
SELECT customername, MAX(LEN(address))
FROM customers
GROUP BY customername
HAVING MAX(LEN(address)) = 13;
或者如果您只需要长度为 13 的客户,也许根本不需要聚合:
SELECT customername
FROM customers
WHERE LEN(address) = 13;