在TEST_DB中,使用AdventureWorks2012中的数据创建以下视图:

时间:2017-06-23 16:05:07

标签: sql sql-server

包含已完成订单的每位客户的全名,送货地址,帐单邮寄地址和应付款总额的视图。列出每个客户的个人订单

=>

go
create view employ as

        select employee.BusinessEntityID,
           firstname + ' ' +isnull( middlename + ' ','') +lastname as 'fullname',
           shippingaddress, billingaddress, totaldue, customer, individualorder    
        from AdventureWorks2012.HumanResources.Employee
   inner join AdventureWorks2012.person.person on employee.businessentityid = person.businessentityid
   inner join AdventureWorks2012.person.Address on employee.businessentityid = Address.AddressID
   inner join AdventureWorks2012.sales.SalesOrderDetail on employee.businessentityid = SalesOrderDetail.SalesOrderID
   inner join AdventureWorks2012.sales.Customer on employee.businessentityid = customer.CustomerID
GO

-- Now select from the view
Select * From employ

注意:我已经编辑了我的查询,但仍然收到了有关送货地址,帐单地址,应付总额和客户的无效列。我是否需要客户专栏?有人可以通过添加或删除我的查询不必要的内容进行更新,以便更正。所以我理解逻辑。

1 个答案:

答案 0 :(得分:0)

根据您的上述解释,我相信您可以通过以下方式解决此问题:

如果要查询视图,请先创建它,然后再Select * From employ

    create view employ as

        select employee.BusinessEntityID,
           firstname + ' ' +isnull( middlename + ' ','') +lastname as 'fullname',
           shippingaddress, billingaddress, totaldue, customer, individualorder    
        from AdventureWorks2012.HumanResources.Employee
        inner join AdventureWorks2012.person.person 
                   on employee.businessentityid = person.businessentityid

GO

-- Now select from the view
Select * From employ