简体   繁体   中英

having clause is not working in sql

I dont understand whats wrong in this statment.

  Select customername,LEN(address) 
  FROM customers group by customername having LEN(address) = 13;

This is the error message HAVING clause (LEN(address)=13) without grouping or aggregation.

Neither address nor LEN(address) is in the GROUP BY . So, you either need to add them or wrap the expressions in an aggregation function:

SELECT customername, MAX(LEN(address))
FROM customers 
GROUP BY customername 
HAVING MAX(LEN(address)) = 13;

Or if you just want customers with a length of 13, perhaps no aggregation is needed at all:

SELECT customername
FROM customers 
WHERE LEN(address) = 13;

Try it with the where clause

  Select customername,LEN(address) as lenadressnamecolumn
  FROM customers where LEN(address) = 13;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM