|
create table A (QXXH int, QXMC nvarchar (10))
insert A select 1, 'Fill in a post'
union all select 2, 'Post approval'
union all select 3, 'Fill in the receipt'
union all select 4, 'Receive Approval'
create table B (XH int, QXXH int, YHMC nvarchar (10))
insert B select 1, 2, '张三'
union all select 2, 3, '张三'
union all select 3, 1, '李四'
union all select 4, 3, '李四'
union all select 5, 4, '李四'
select tmp. *, do you have this permission = case when B.XH is null then 'False' else 'True' end from
(
select * from
(select distinct YHMC from B) as B
cross join A
tmp
left join B on tmp.QXXH = B.QXXH and tmp.YHMC = B.YHMC
--result
Does YHMC QXXH QXMC have this permission
---------- ----------- ---------- ------
Li Si 1 Post True
Li Si 2 Posting approval False
Li Si 3 Received True
Li Si 4 Receive receipt approval True
Zhang San 1 Post False
Zhang San 2 Posting approval True
Zhang San 3 Receipt Fill in True
Zhang San 4 Incoming Approval False
(8 row (s) affected) |
|