这是表格的示例:
客户
╔══════════╦════════════╗
║ GROUP_ID ║ GROUP_NAME ║
╠══════════╬════════════╣
║ abc ║ xex ║
║ def ║ tet ║
╚══════════╩════════════╝
团队
╔════════╦════════════╗
║ ACT_ID ║ GROUP_NAME ║
╠════════╬════════════╣
║ 44 ║ xex ║
║ 32 ║ tet ║
╚════════╩════════════╝
行动
╔════╦════════════╗
║ ID ║ STATE ║
╠════╬════════════╣
║ 44 ║ complete ║
║ 58 ║ incomplete ║
╚════╩════════════╝
请注意,act_id
在表teams
中也存在于表actions
中id
我想选择一个有两列的表:group_id
和group_name
,其中每个group_name
都有act_id
一个完整 state
的.
我正在做类似的事情:
SELECT group_id AND group_name
FROM clients
WHERE group_name IN (SELECT group_name
FROM teams, actions
WHERE teams.act_id = actions.id
AND actions.state IS complete)
这个对吗 ?
我也想到了类似的东西
SELECT group_id AND group_name
FROM clients
WHERE group_name IN (SELECT group_name
FROM teams
WHERE act_id IN (SELECT id
FROM actions
WHERE teams.act_id = actions.id.
AND state IS complete))
以上是否正确?
我要找的桌子显然是这张:
╔══════════╦════════════╗
║ GROUP_ID ║ GROUP_NAME ║
╠══════════╬════════════╣
║ abc ║ xex ║
╚══════════╩════════════╝