在这里摆弄桌子
我正在使用以下 sql 和小提琴中的表来检查用户是否已达到借用限制。这里的问题是,如果提供了无效的项目编号,则返回 NULL,如果用户没有借过任何项目,则返回 NULL。这样,我无法判断是否提供了无效的项目编号,或者用户是否实际上没有借过任何书籍。检查是否提供了无效的项目编号或成员实际上没有在该类别下借任何东西的好方法是什么?
set @mId = 3 //Has not borrowed anything till now.
set @id = 21; //This item does not appear in the collection_db table and is therefore invalid.
set @country = 'US';
SELECT col1.id, col1.holder, col2.borrowMax maxLimit, count(lend.borrowedId) as `count`
FROM collection_db col1
INNER JOIN collection_db col2
ON col1.holder = col2.id
INNER JOIN lendings lend
ON col1.holder = lend.holder and col1.country = lend.country
WHERE col1.id = @id and col1.country = @country
AND col2.category = 10
AND lend.memId = @mId and lend.country = @country