我有2个MySQL表。
id | sellDate
1 | 2011-05-30
2 | 2011-09-15
3 | 2016-03-04
4 | 2017-05-06
5 | 2018-04-16
id | activation | program_id
1 | 2011-05-30 | 1
2 | 2011-09-15 | 2
3 | 2016-03-04 | 3
4 | 2017-05-06 | 4
programs
表包含客户购买程序的时间,activation
表包含客户激活程序的时间。我想在客户购买ID为5的程序的地方打印该客户,但不激活它,因此程序ID 5不在激活表中。我该怎么解决?
答案 0 :(得分:1)
SELECT id FROM programs WHERE id NOT IN (SELECT program_id FROM activation);
如果您使用具有更好JOIN性能的DBMS:
SELECT id FROM programs p LEFT OUTER JOIN activation a ON p.id=a.program_id WHERE a.program_id IS NULL;
答案 1 :(得分:0)
SELECT id FROM programs WHERE id NOT IN (SELECT program_id FROM activation);