gpt4 book ai didi

mysql - 如何根据列的条件连接两个表?

转载 作者:行者123 更新时间:2023-11-29 09:46:05 27 4
gpt4 key购买 nike

我有两张 table :

表A:

id | key | price

表B:

id | key | min | max

我希望表B中的行minma​​x列包含表A中的price列.换句话说,价格大于最小值且小于最大值。
我使用了这段代码,但没有返回真实的结果:

SELECT * FROM B INNER JOIN A ON A.key=B.key where A.price > B.min AND A.price < B.max;

最佳答案

使用此 mysql 查询来获取结果,并确保将价格列设置为 INT 或 FLOAT。

SELECT 
table1.id,table1.key,table1.price,
table2.min,table2.max
FROM
table1
INNER JOIN
table2 ON table1.key = table2.key
AND (table1.price > table2.min
AND table1.price < table2.max);

关于mysql - 如何根据列的条件连接两个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55634063/

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