使用逻辑运算符:AND,OR,编写一个返回1996年7月下达的订单的查询 作者:Nancy Davolio,Janet Leverling和Steven Buchanan。列出订单ID,员工ID和 订单日期。由employeeID订购结果集。 Northwind数据库
答案 0 :(得分:1)
SELECT O.OrderID
,E.EmployeeID
,O.OrderDate
FROM dbo.Orders O INNER JOIN dbo.Employees E
ON O.EmployeeID = E.EmployeeID
WHERE YEAR(O.OrderDate) = 1996
AND MONTH(O.OrderDate)= 7
AND E.FirstName IN ('Nancy','Janet', 'Steven')
严格使用AND和OR运算符
SELECT O.OrderID
,E.EmployeeID
,O.OrderDate
FROM dbo.Orders O INNER JOIN dbo.Employees E
ON O.EmployeeID = E.EmployeeID
WHERE YEAR(O.OrderDate) = 1996
AND MONTH(O.OrderDate)= 7
AND
( E.FirstName = 'Nancy'
OR E.FirstName = 'Janet'
OR E.FirstName = 'Steven'
)