有客户和节日的桌子。每个节日每年都会发生(如新年)。但并不是每个客户都被邀请参加任何节日。
我需要找到女性客户,她们现在在festival1 上被邀请,但在festival2 上没有被邀请。
Table "clients"
+-----+--------------+-----------+---------+-----+
| id | name | email | adress | sex |
+-----+--------------+-----------+---------+-----+
| 1 | Ivan | iva@ya.su | NY city | m |
| 2 | Michael | lad@ya.su | LA | m |
| 3 | Anna | al@ya.su | LA | w |
| ...
+-----+--------------+-----------+---------+-----+
Table festivals
+-----+------------+-------+
| id | name | date |
+-----+------------+-------+
| 1 | festival1 | 8-03 |
| 2 | festival2 | 23-02 |
| 3 | festival3 | 1-01 |
| ...
+-----+------------+-------+
Talbe "invitations"
+--------+----------+------+
| client | festival | year |
+--------+----------+------+
| 1 | 2 | 2013 |
| 3 | 1 | 2009 |
| ...
+--------+----------+
我开始做类似这个查询的事情,但需要更正:
SELECT name
FROM clients, festivals, invitations
WHERE clients.sex = w
AND festivals.name = festival1
AND clients.id = invitations.client
AND invitations.year = 2013