Reputation: 33
I have a database and I'm tasked to find out how many times the book 'Hood' has been borrowed. I know it's twice
I have to write SQL to return how many times it was borrowed. So far I have this but it only returns how many unique Books there are not how many times 'Hood' was borrowed
select count('Hood') as lenttimes
from
(
select distinct bTitle from borrow
);
Upvotes: 3
Views: 14662
Reputation: 214
This will return number of rows in your table:
SELECT COUNT(*) FROM borrow WHERE bTitle='Hood';
Upvotes: 0
Reputation: 2338
Hoping, i understood your problem correctly.
Please check below query.
select count(0) from borrow where btitle='Hood'
Upvotes: 0
Reputation: 1269753
I think you want:
select sum(iff(btitle = 'Hood', 1, 0)) as lenttimes
from borrow;
This uses sum(iff())
so you can count more than one title (in another column).
Upvotes: 3
Reputation: 311228
All you need to do is apply a where
clause and count the results:
SELECT COUNT(*)
FROM borrow
WHERE bTitle = 'Hood'
Upvotes: 2