成都网站建设设计

将想法与焦点和您一起共享

SQLServerinsert与Select组合使用的方法

SQL Server insert语句是SQL中最常见也是最重要的语句之一,下文将为您解读SQL Server insert与Select组合使用的方法,供您参考。

在定州等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站制作、网站设计 网站设计制作按需制作,公司网站建设,企业网站建设,高端网站设计,成都全网营销推广,成都外贸网站制作,定州网站建设费用合理。

SQL Server中有示例数据库Northwind。新建表Sales用于存储销售信息,字段为EmployeeID,ProductID,SupplierID,CustomerID,OrderDate,UnitPrice,Total,Quantity,Discount。

下面的语句从Orders,Order Details, Employees,Products, Suppliers, Customers表选择相应的

数据插入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.Discount

from Orders o,[Order Details] od, Employees e,

Products p, Suppliers s, Customers c

where (o.OrderID = od.OrderID) and

(o.EmployeeID = e.EmployeeID) and

(o.CustomerID = c.CustomerID) and

(od.ProductId = p.ProductID) and

(p.SupplierID = s.SupplierID);


分享文章:SQLServerinsert与Select组合使用的方法
转载注明:https://chengdu.cdxwcx.cn/article/dpoopso.html