gpt4 book ai didi

php - 努力将 WHERE 子句添加到 INNER JOIN

转载 作者:行者123 更新时间:2023-11-29 14:35:54 28 4
gpt4 key购买 nike

我有一个查询,应该从每个 backend_hotels_id date_startpackage_supplier 中选择最低的 price_per_pax_after_tax 并且在我添加 WHERE 子句之前,这似乎一直有效。

这是查询:

SELECT e.price_per_pax_after_tax, e.hotel_score, e.package_id, e.package_type
FROM packages_sorted_YQU e
INNER JOIN (
SELECT db_id, MIN( price_per_pax_after_tax ) AS lowest_price, package_id, hotel_score
FROM `packages_sorted_YQU`
WHERE `package_type` IN ('9', '10', '18')
AND `package_duration` IN ('6', '8', '12')
GROUP BY
`date_start` , `package_supplier` , `backend_hotels_id`
) AS j
ON j.db_id = e.db_id
AND j.lowest_price= e.price_per_pax_after_tax
AND j.hotel_score = e.hotel_score
AND j.package_id = e.package_id;

表格很大,但列出的所有字段都是 INT,除了 date_start 是 DATE

导致问题的where子句是:

WHERE `package_type` IN ('9', '10', '18') 
AND `package_duration` IN ('6', '8', '12')

如果没有 where 子句,我会得到超过 400 个结果,如果有 where 子句,我会得到零个结果:( 非常感谢任何帮助。

最佳答案

如果您的列 package_typepackage_duration 的类型为 int,则不必将值包装在 ' 就像字符串一样。

SELECT e.price_per_pax_after_tax, e.hotel_score, e.package_id, e.package_type
FROM packages_sorted_YQU e
INNER JOIN (
SELECT db_id, MIN( price_per_pax_after_tax ) AS lowest_price, package_id, hotel_score
FROM `packages_sorted_YQU`
WHERE `package_type` IN (9, 10, 18)
AND `package_duration` IN (6, 8, 12)
GROUP BY
`date_start` , `package_supplier` , `backend_hotels_id`
) AS j
ON j.db_id = e.db_id
AND j.lowest_price= e.price_per_pax_after_tax
AND j.hotel_score = e.hotel_score
AND j.package_id = e.package_id;

关于php - 努力将 WHERE 子句添加到 INNER JOIN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9061882/

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