是否有可能在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
答案 0 :(得分:1)
您需要使用SQL IN运算符来过滤多个值。
所以你的查询应该是:
SELECT *
FROM `services`
WHERE servide IN ('wifi','pulizia','parking','ombrellone','driver','colazione') AND active = 1
答案 1 :(得分:1)
只需使用IN
SELECT * FROM `services`
WHERE service_id IN ('wifi','pulizia','parking','ombrellone','driver','colazione') AND active = 1
答案 2 :(得分:1)
你会使用IN:
SELECT *
FROM services
WHERE service IN ('wifi','pulizia','parking','ombrellone','driver','colazione')
AND active = 1;