有条款面临的问题
Facing issue in having clause
select *
from db_user
order by date_created asc OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY
having full_name like 'Admin%';
获取错误:
[S0001][156] Incorrect syntax near the keyword 'having'.
如何解决这个问题,因为 'where' 子句也给出错误。
having
用于过滤掉来自 group by
子句的分组结果。如果您只想过滤掉行,您应该使用 where
子句。请注意,它应该出现在 之前 order by
子句:
SELECT *
FROM db_user
WHERE full_name LIKE'Admin%' -- Here!
ORDER BY date_created ASC OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY
HAVING 用于带有 groupby 语句的查询,以根据 聚合列 的值过滤结果。您应该改用 WHERE。
正确的查询是:
select *
from db_user
where full_name like 'Admin%'
order by date_created asc OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY
;
select *
from db_user
order by date_created asc OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY
having full_name like 'Admin%';
获取错误:
[S0001][156] Incorrect syntax near the keyword 'having'.
如何解决这个问题,因为 'where' 子句也给出错误。
having
用于过滤掉来自 group by
子句的分组结果。如果您只想过滤掉行,您应该使用 where
子句。请注意,它应该出现在 之前 order by
子句:
SELECT *
FROM db_user
WHERE full_name LIKE'Admin%' -- Here!
ORDER BY date_created ASC OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY
HAVING 用于带有 groupby 语句的查询,以根据 聚合列 的值过滤结果。您应该改用 WHERE。
正确的查询是:
select *
from db_user
where full_name like 'Admin%'
order by date_created asc OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY
;