gpt4 book ai didi

mysql - SQL : how to select different rows where values are equal to an set of values?

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:33 28 4
gpt4 key购买 nike

是否可以在 SQL 中实现类似的功能?

SELECT * FROM `services` WHERE servide_id = ('wifi','pulizia','parking','ombrellone','driver','colazione') AND active = 1

例如我有一个表:

service   |price   |active
wifi €60 0
park €20 1
option €30 1
another €40 1

查询必须执行如下操作:

1) SELECT * FROM service
2) loop through 'service' column and select WHERE service is = to any value on array
3) check if active is = 1

我想要什么?

query:
SELECT * FROM services WHERE service = ('wifi','park') AND active = 1

result:
service |price |active
park €20 1

感谢您的帮助,我刚刚开始使用 SQL :D

最佳答案

您需要使用 SQL IN运算符过滤多个值。

所以你的查询应该是:

SELECT * 
FROM `services`
WHERE servide IN ('wifi','pulizia','parking','ombrellone','driver','colazione') AND active = 1

关于mysql - SQL : how to select different rows where values are equal to an set of values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25328921/

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