我正在尝试让我的输出显示比总平均次数多的旅行的客户。总体平均值为2.5。任何有关正确方向的帮助/提示都会非常感激。
SELECT
customer.cus_fname "Customer First Name",
customer.cus_lname "Customer Last Name",
AVG(count(charter.char_trip)) > 3 "Number of Flights"
FROM chartname.customer
LEFT JOIN chartname.charter ON customer.cus_code= charter.cus_code
GROUP BY customer.cus_fname, customer.cus_lname;
答案 0 :(得分:2)
您正在寻找having
子句:
SELECT cu.cus_fname "Customer First Name", cu.cus_lname "Customer Last Name",
count(ch.char_trip) "Number of Flights"
FROM chartname.customer cu LEFT JOIN
chartname.charter ch
ON cu.cus_code = ch.cus_code
GROUP BY cu.cus_fname, cu.cus_lname
HAVING COUNT(ch.char_trip) >= 3;
过滤条件包含where
或having
条款,而不是select
条款。