JOIN SQL查询日期

问题描述:

非常感谢...这是我的最后一个问题:JOIN SQL查询日期

我有三个表有以下栏目:

  1. 客户:

客户名称姓氏

  1. 个交易:

反式ID的ClientID RepresentativeID订购日期

  1. 代表:
  2. 代表ID名姓

    I需要显示的所有交易信息,以及在特定日期发生的代表名称和客户名称。这个查询是否正确?

    SELECT * 
    FROM [Transactions], Clients.first name, Clients.last name,  Representatives.first name, Representatives. last name 
    INNER JOIN [Clients] 
    ON Transactions.ClientID= Clients.Client ID 
    INNER JOIN [Representatives] 
    ON Transactions.RepresntativeID = Representatives.Represntative ID 
    WHERE Transactions.OrderDate BETWEEN '1996-09-18' AND '1996-11-27'; 
    

    这是正确的还是我得到了所有错误?

开始=>

WHEREONORDER BY

;在去年底没有中间

SELECT * 
FROM [Orders] 
JOIN [Customers] 
    ON Orders.CustomerID = Customers.CustomerID 
WHERE Orders.OrderDate BETWEEN '1996-09-18' AND '1996-11-27' 
ORDER BY Customers.CustomerName; 
+0

非常感谢......这是我的最后一个问题: – OBZ

SELECT Clients.[first NAME] AS ClientFirstName 
     ,Clients.[last NAME] AS ClientLastName 
     ,Representatives.[first NAME] AS RepresentativesFirstName 
     ,Representatives.[last NAME] AS RepresentativesLastName 
     ,Transactions.* 
FROM [Transactions] 
INNER JOIN [Clients] 
    ON Transactions.ClientID = Clients.Client ID 
INNER JOIN [Representatives] 
    ON Transactions.RepresntativeID = Representatives.Represntative ID 
WHERE Transactions.OrderDate BETWEEN '1996-09-18' 
     AND '1996-11-27'; 

您预期的结果列应该把什么它SELECT之前。 From是你的表或数据集。

另外,您可以使用别名来简化SQL,如下所示。

SELECT c.[first NAME] AS ClientFirstName 
     ,c.[last NAME] AS ClientLastName 
     ,r.[first NAME] AS RepresentativesFirstName 
     ,r.[last NAME] AS RepresentativesLastName 
     ,t.* 
FROM [Transactions] t 
INNER JOIN [Clients] c 
    ON t.ClientID = c.Client ID 
INNER JOIN [Representatives] r 
    ON t.RepresntativeID = r.Represntative ID 
WHERE t.OrderDate BETWEEN '1996-09-18' 
     AND '1996-11-27';