我有3个表:Book
,Customer
和Trans
。我正在尝试编写一个选择查询,报告9月份购买图书的所有人的Name
和Book
标题。表已成功创建,并且所有数据都在其中,但我无法使此选择查询生效。我尝试了一切。这就是我所拥有的:
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';
我也试图避免重复。
答案 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