0

我有以下表格布局(用于列):

IDrenterID BookID dateOfRental

我被要求制作一个报告页面,我可以在其中查看每个renterID 在特定日期租用了多少本书。现在我什至不确定这是否可能,但我想我会问你们至少一个方向或类似的片段,我可以从中学习?

4

3 回答 3

1

我假设您希望在特定日期这样做:

SELECT 
   COUNT(*) BookCount, 
   renterId, 
   dateOfRental 
FROM
   someTable
WHERE
   dateOfRental = [a certain date]
GROUP BY 
   renterId 
于 2013-07-05T18:09:43.547 回答
1

你可以通过简单的 group by 来做到这一点:

SELECT renterID , dateOfRental , COUNT(*) AS TOTALCOUNT 
FROM TABLE1
GROUP BY renterID , dateOfRental 
于 2013-07-05T18:10:10.033 回答
0

就像是:

SELECT
   renterID
 , COUNT(DISTINCT BookID)
FROM
   your_table
WHERE
     dateOfRental = 'the_date'
-- or if you want a date period:  dateOfRental BETWEEN start_date AND end_date
GROUP BY
   renterID
;
于 2013-07-05T18:09:11.310 回答