SQL Server查询获得独特的Page_Name

时间:2017-02-17 10:21:14

标签: sql sql-server

如何使用此查询

来区分Page_Name
   Select A.UserId,Page_Name,Region_Name, Content_Name,Chart_Src
   from  DWH_DBPages A 
   LEFT OUTER JOIN DWH_DashBoardA B ON A.sysRegionSno=B.sysRegionSno 
   LEFT OUTER JOIN DWH_DashBoardB C ON B.sysContentSno=C.sysContentSno 
   LEFT OUTER JOIN DWH_DashboardC D ON C.sysTypeSno=D.sysTypeSno
   LEFT OUTER JOIN DWH_DashboardD E ON D.sysChartSno=E.sysChartSno
   WHERE A.UserId = 'xxxxxxxxx' AND A.sysMenuSno = 'xxxx'

表格结构

DWH_DBPages A      
=============    
sysPageSno
Page_Name
sysMenuSno
Page_Status
Parent_Div
sysRegionSno
UserId
Created_Date


DWH_DashBoardA
==============
sysRegionSno
Region_Name
Region_Type
sysContentSno
UserId
Created_Date

DWH_DashboardC
===============
sysContentSno
Content_Name
sysTypeSno
UserId
Created_Date

DWH_DashboardD
===============
sysChartSno
Chart_Name
Chart_Src
Chart_Procedure
UserId

1 个答案:

答案 0 :(得分:1)

select distinct( Page_Name) 
from (Select A.UserId,Page_Name,Region_Name, Content_Name,Chart_Src 
     from DWH_DBPages A 
     LEFT OUTER JOIN DWH_DashBoardA B ON A.sysRegionSno=B.sysRegionSno 
     LEFT OUTER JOIN DWH_DashBoardB C ON B.sysContentSno=C.sysContentSno 
     LEFT OUTER JOIN DWH_DashboardC D ON C.sysTypeSno=D.sysTypeSno 
     LEFT OUTER JOIN DWH_DashboardD E ON D.sysChartSno=E.sysChartSno 
     WHERE A.UserId = 'xxxxxxxxx' 
     AND A.sysMenuSno = 'xxxx')aa