gpt4 book ai didi

Mysql多次选择COL以获得不同的值

转载 作者:行者123 更新时间:2023-11-29 14:36:52 26 4
gpt4 key购买 nike

这是表结构:

ID PID KEY VALUE
1 2 CITY NEW YORK
2 2 COUNTRY UNITED STATES
3 2 STATE NEW YORK
4 1 CITY NEW JERSEY

等等..我想要的是获取/过滤结果,如

Where (KEY = CITY and VALUE = NEW YORK) 
AND (key = country AND VALUE= UNITED STATES)

这将返回空行!

最佳答案

您需要一个 self JOIN

SELECT t1.*
FROM my_table t1
INNER JOIN my_table t2 ON t1.pid = t2.pid
WHERE t1.key = 'city' and t1.value = 'new york'
AND t2.key = 'country' and t2.value = 'united states';

关于Mysql多次选择COL以获得不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8846645/

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