在这个查询中,我指定了我想要返回的汽车型号(硬编码)。所以下面的 SQL为每个模型返回一条记录:
SELECT
*
FROM
main
WHERE
(
(marka_name = 'SUBARU' AND model_name = 'IMPREZA' AND (kuzov = 'GC8' OR kuzov = 'GF8')) OR
(marka_name = 'MAZDA' AND model_name = 'RX-7' AND kuzov = 'FD3S') OR
(marka_name = 'MITSUBISHI' AND model_name = 'LANCER' AND (kuzov = 'CN9A' OR kuzov = 'CP9A')) OR
(marka_name = 'NISSAN' AND model_name = 'SKYLINE' AND (kuzov = 'ER34' OR kuzov = 'BCNR33')) OR
(marka_name = 'NISSAN' AND model_name = 'SILVIA' AND kuzov = 'S14') OR
(marka_name = 'TOYOTA' AND model_name = 'CELICA' AND kuzov = 'ST205') OR
(marka_name = 'TOYOTA' AND model_name = 'ARISTO' AND kuzov = 'JZS161') OR
(marka_name = 'MITSUBISHI' AND model_name = 'DELICA' AND (kuzov = 'PE8W' OR kuzov = 'PD8W' OR kuzov = 'PF8W'))
)
AND
(rate != 'RA' AND rate != 'RR' AND rate != 'A1' AND rate != 'A' AND rate != 'R' AND rate >= '3')
AND
(mileage >= 0 AND mileage <= 150000)
AND
(year >= 1990 AND year <= 1998)
GROUP BY
model_name
ORDER BY
mileage ASC,
rate DESC
现在是否有可能在没有联合的情况下让此 SQL 返回由某个字段指定的多个模型。例子:
GROUP BY
model_name
HAVING COUNT(model_name) = 2
ORDER BY
mileage ASC,
rate DESC
我知道 HAVING COUNT 没有意义,但我需要一种方法来指定每个模型返回多少汽车。