成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

SQL Server中Insert與Select的組合使用

瀏覽:158日期:2023-11-04 08:46:42

SQL Server中有示例數(shù)據(jù)庫Northwind。新建表Sales用于存儲(chǔ)銷售信息,字段為EmployeeID,ProductID,SupplierID,CustomerID,OrderDate,UnitPrice,Total,Quantity,Discount。

下面的語句從Orders,Order Details, Employees,Products, Suppliers, Customers表選擇相應(yīng)的

數(shù)據(jù)插入Sales表:

insert into Sales(EmployeeID,ProductID,SupplierID,CustomerID,OrderDate,UnitPrice,Total,Quantity,Discount) select e.EmployeeID, p.ProductID, s.SupplierID,c.CustomerID, o.OrderDate, od.UnitPrice,od.Quantity*od.UnitPrice*(1.0-od.Discount)Total,Od.Quantity, od.Discountfrom Orders o,[Order Details] od, Employees e,Products p, Suppliers s, Customers cwhere (o.OrderID = od.OrderID) and(o.EmployeeID = e.EmployeeID) and(o.CustomerID = c.CustomerID) and(od.ProductId = p.ProductID) and(p.SupplierID = s.SupplierID);go

標(biāo)簽: Sql Server 數(shù)據(jù)庫