我想要一个 SELECT 查询,它可以获取 user1 和 user2 的 8 个特定组合(并且 user2 和 user1 的组合也值得拥有,而不是多余的)。“IN”声明似乎是值得的。
直接相关的问题。1.“WHERE IN”语句可以嵌套吗?
- 如果没有,我如何最有效/最容易地构建一个查询以便我可以指定(对于 4 对,其中 user1 和 user2 切换位置 - 8 个组合):
(where user1 = billy AND user2 = sue) OR (where user1 = sue AND user2 =billy) OR (user1 = jack AND user2 = jill) OR (user1 = jill AND user2 = jack)
...等?
[此时运行查询和 grep 相关信息似乎更容易。]
目前的想法:
sqlite3 -header -separator , some.db "SELECT DISTINCT programquality.time, simscores.user1, simscores.user2, simscores.simscore, programquality.gf, programquality.ga, programquality.pq FROM simscores LEFT JOIN programquality ON programquality.time = simscores.time AND programquality.username = simscores.user1 WHERE programquality.pq IS NOT NULL WHERE simscores.user1 IN ("abraham","billy","carl","dave","ethan","frank","george","harry") WHERE simscores.user2 IN ("abraham","billy","carl","dave","ethan","frank","george","harry");"
我用过这个,但显示了一些不相关的数据。
sqlite3 -header -separator , some.db 'SELECT DISTINCT programquality.time, simscores.user1, simscores.user2, simscores.simscore, programquality.gf, programquality.ga, programquality.pq FROM simscores LEFT JOIN programquality ON programquality.time = simscores.time AND programquality.username = simscores.user1 WHERE (simscores.user1 = "billy" OR simscores.user1 = "suzy" OR simscores.user1 = "john") AND (simscores.user2 = "billy" OR simscores.user2 = "suzy" OR simscores.user2 = "john") AND programquality.pq IS NOT NULL AND programquality.time IS NOT NULL;'