SQL新手,我遇到了Select查询的问题

时间:2014-03-14 16:46:23

标签: mysql

我有3个表:BookCustomerTrans。我正在尝试编写一个选择查询,报告9月份购买图书的所有人的NameBook标题。表已成功创建,并且所有数据都在其中,但我无法使此选择查询生效。我尝试了一切。这就是我所拥有的:

SELECT DISTINCT c.Name, b.Title, t.TDate
FROM Customer as c, Book as b, Trans as t;
WHERE c.ID=t.ID AND b.BookID=t.BookID and t.TDate < '2003-10-01';

我也试图避免重复。

1 个答案:

答案 0 :(得分:2)

SELECT c.Name, b.Title
FROM Customer as c
JOIN Trans as t ON c.ID = t.ID
JOIN Book as b ON b.BookID = t.BookID
WHERE t.TDate >= '2003-10-01' and t.TDate < '2003-11-01'
GROUP BY c.Name, b.Title