gpt4 book ai didi

mysql - 给定单个字段中的内容,如何执行在同一行中的不同字段中传递值的查询?

转载 作者:行者123 更新时间:2023-11-29 06:09:20 25 4
gpt4 key购买 nike

member  purchase   fruit
1 1 apple
1 2 apple
1 3 banana
1 4 banana
2 1 apple
2 2 apple
2 3 banana
2 4 banana

如何生成以下结果集?

SELECT * FROM table wherefruit =(记录中的水果,其中member = ?且purchase = ?)

例如,如果 member = 2purchase = 3,结果集将为

member  purchase   fruit
2 3 banana
2 4 banana

最佳答案

SELECT * FROM table where fruit = (the fruit in the record where member = ? and purchase = ?)

你快要拥有它了。试试这个:

SELECT * FROM yourtable WHERE fruit =
(
SELECT fruit FROM yourtable WHERE member = ? AND purchase = ?
)

您可能还想将 AND member = ? 添加到查询末尾,正如 Jonas Heidelberg 在评论中提到的那样。

关于mysql - 给定单个字段中的内容,如何执行在同一行中的不同字段中传递值的查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9857198/

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