27,579
社区成员
发帖
与我相关
我的任务
分享
slect B
from
(select distinct B FROM TABLE WHERE A='甲'
union all
select distinct B FROM TABLE WHERE A='乙') as a
group by B
having count(*)=1
SELECT *
FROM ( SELECT t1.A AS t1A ,
t2.A AS t2A
FROM 表 t1
left JOIN 表 t2 ON t1.B = t2.B
WHERE t1.A = '甲'
AND t2.A = '乙'
union
SELECT t1.A AS t1A ,
t2.A AS t2A
FROM 表 t1
left JOIN 表 t2 ON t1.B = t2.B
WHERE t1.A = '乙'
AND t2.A = '甲'
) t
WHERE t.t1A IS NULL
OR t.t2A IS NULL
with t1(序号, 图书馆名, 书名) as
(
select 1, '甲', '111' union all
select 2, '甲', '222' union all
select 3, '乙', '111' union all
select 4, '乙', '222'
)
select case when COUNT(*)=0 then '是' else '否' end from
(select * from t1 where 图书馆名='甲') a
full join
(select * from t1 where 图书馆名='乙') b
on a.书名=b.书名
where a.序号 is null or b.序号 is null
select a.library,b.book from table a
inner join (
select book from table group by book having count(book)>1
) b on a.nook=b.book
order by b.book,a.library
这样你能明白了没select * from
(select * from 书的记录 where A='图书馆甲') a,
(select * from 书的记录 where A='图书馆乙') b
where a.B=b.B and a.数量=b.数量
select * from
(select * from 书的记录 where A='图书馆甲') a,
(select * from 书的记录 where A='图书馆乙') b
where a.A=b.A and a.B=b.B and a.数量=b.数量
IF ( EXISTS ( SELECT *
FROM ( SELECT t1.A AS t1A ,
t2.A AS t2A
FROM 表 t1
FULL JOIN 表 t2 ON t1.B = t2.B
WHERE t1.A = '甲'
AND t2.A = '乙'
) t
WHERE t.t1A IS NULL
OR t.t2A IS NULL ) )
BEGIN
PRINT '不完成相同'
END
ELSE
BEGIN
PRINT '完成相同'
END