我遇到了关于左连接的问题
我有两张桌子:
table: books{
isbn pk,
title,
author,
date_added
}
table: books_batch{
isbn pk,
date_added
}
表books_batch用于存储当前正在处理的所有书籍,并且是为简单实现并行处理的互斥解决方案而创建的。
SELECT b.isbn, b.binding, b.publication_date, b.rank,
IF(bb.date_added IS NULL, 0, 1) AS active
FROM books b
LEFT JOIN books_batch bb ON bb.isbn = b.isbn
WHERE b.rank IS NOT NULL
AND b.rank > 30000
AND b.publication_date IS NOT NULL
ORDER BY b.rank ASC
我想在名为active的查询中创建一个新字段,表示bookbook表中是否存在book记录
是否有更好的解决方案来检查记录是否存在,而不是检查date_added是否存在。
IF(bb.date_added IS NULL, 0, 1) AS active
类似
IF(bb NOT EXISTS, 0, 1) AS active