Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7865
  • 博文数量: 11
  • 博客积分: 230
  • 博客等级: 二等列兵
  • 技术积分: 120
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-11 16:03
文章分类

全部博文(11)

文章存档

2011年(11)

我的朋友
最近访客

分类: Mysql/postgreSQL

2011-03-07 13:04:12

select * from (select rc.RightCode,rc.RightName,rt.RightType,rt.TypeName,rt.TableName from dbo.RightCode as rc cross join dbo.RightType as rt)aa 
cross join dbo.Devices where aa.RightType=1
多表连接查询
select ViewRoleRightsDetail.*,devices.Name from
(SELECT     dbo.RightCode.RightName, dbo.RightType.TypeName, dbo.Roles.RoleID, dbo.RightsNew.RightType, dbo.RightsNew.RightItemId,
                      dbo.RightType.TableName, dbo.RightCode.RightCode, dbo.RoleRightsNew.RightId
FROM         dbo.Roles INNER JOIN
                      dbo.RoleRightsNew ON dbo.Roles.RoleID = dbo.RoleRightsNew.RoleId INNER JOIN
                      dbo.RightsNew ON dbo.RoleRightsNew.RightId = dbo.RightsNew.RightId INNER JOIN
                      dbo.RightType ON dbo.RightsNew.RightType = dbo.RightType.RightType INNER JOIN
                      dbo.RightCode ON dbo.RightsNew.RightCode = dbo.RightCode.RightCode) ViewRoleRightsDetail
left join devices on  devices.DeviceID = ViewRoleRightsDetail.rightItemId
where tablename='devices'
UNION ALL
select ViewRoleRightsDetail.*,sensors.Name
from (SELECT     dbo.RightCode.RightName, dbo.RightType.TypeName, dbo.Roles.RoleID, dbo.RightsNew.RightType, dbo.RightsNew.RightItemId,
                      dbo.RightType.TableName, dbo.RightCode.RightCode, dbo.RoleRightsNew.RightId
FROM         dbo.Roles INNER JOIN
                      dbo.RoleRightsNew ON dbo.Roles.RoleID = dbo.RoleRightsNew.RoleId INNER JOIN
                      dbo.RightsNew ON dbo.RoleRightsNew.RightId = dbo.RightsNew.RightId INNER JOIN
                      dbo.RightType ON dbo.RightsNew.RightType = dbo.RightType.RightType INNER JOIN
                      dbo.RightCode ON dbo.RightsNew.RightCode = dbo.RightCode.RightCode) ViewRoleRightsDetail
left join sensors on  sensors.SensorID = ViewRoleRightsDetail.rightItemId
where tablename='sensors'

阅读(325) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~