gpt4 book ai didi

sql - 如何使这个 mysql 子查询工作

转载 作者:行者123 更新时间:2023-11-29 09:13:50 26 4
gpt4 key购买 nike

SELECT c.noreg AS noreg, count( * ) AS jumlah
FROM kamar a, reservasi b, register c, identitas_psn d, sub_unit_kamar e
WHERE a.idkamar = b.kamar
AND b.noreg = c.id_reg_lengkap
AND c.norm = d.norm
AND c.idunit = e.id_subunit
AND c.noreg NOT
IN (

SELECT noreg
FROM register_keluar
)
AND (
c.idunit LIKE '20%'
)
AND jumlah > 1
GROUP BY noreg
ORDER BY jumlah DESC

//错误是:AND jumlah > 1

最佳答案

jumlah > 1 移至 HAVING 子句,例如:

...
GROUP BY ...
HAVING jumlah > 1
ORDER BY ...

http://en.wikipedia.org/wiki/Having_(SQL ):

A HAVING clause in SQL specifies that an SQL SELECT statement should only return rows where aggregate values meet the specified conditions.

关于sql - 如何使这个 mysql 子查询工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4765560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com