怎么用SQL表达从“Orders,Order_Details,products中查出OrderNumber、CutomerID、ProductName”
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 23:13:40
怎么用SQL表达从“Orders,Order_Details,products中查出OrderNumber、CutomerID、ProductName”
怎么用SQL表达从“Orders,Order_Details,products中查出OrderNumber、CutomerID、ProductName”
怎么用SQL表达从“Orders,Order_Details,products中查出OrderNumber、CutomerID、ProductName”
/*
从“Orders,Order_Details,products中查出OrderNumber、CutomerID、ProductName”
*/
--不要问这么基本的问题好不
DECLARE @orders TABLE(OrderNumber VARCHAR(20),CutomerID INT,CustName VARCHAR(50))
DECLARE @order_details TABLE(OrderNumber VARCHAR(20),DetID int,ProID int,ProductName varchar(50))
INSERT INTO @orders(OrderNumber,CutomerID,CustName)
SELECT 'ord11',22,'test22' UNION ALL
SELECT 'ord22',33,'test33'
INSERT INTO @order_details(OrderNumber,DetID,ProID,ProductName)
SELECT 'ord11',1,100,'pro100' UNION ALL
SELECT 'ord11',2,200,'pro200' UNION ALL
SELECT 'ord22',1,200,'pro200'
SELECT o.OrderNumber,o.CutomerID,d.ProductName
FROM @orders AS o,@order_details AS d
WHERE o.OrderNumber = d.OrderNumber