用SQL语句查询表中数据,希望得到在相同单位下,有不同工资的单位的信息 5
希望得到表中公司2的所有信息,包括(单位ID,名称,员工姓名,工资),公司1中所有工资都相同,所以不需要公司2信息...
希望得到表中公司2的所有信息,包括(单位ID,名称,员工姓名,工资),公司1中所有工资都相同,所以不需要公司2信息
展开
1个回答
展开全部
select aaa.* from (
SELECT a.ORGNAME,a.pay,COUNT(*) AS sl FROM TABLE_TEST a
where
a.ID=1
GROUP BY
a.ORGNAME,a.pay
HAVING
COUNT(*)=1
union all
SELECT b.ORGNAME,b.pay,COUNT(*) AS sl FROM TABLE_TEST b
where
b.ID=2
GROUP BY
b.ORGNAME,b.pay
HAVING
COUNT(*)=1) aa,TABLE_TEST aaa where aa.ORGNAME=aaa.ORGNAME and aa.pay=aaa.PAY
SELECT a.ORGNAME,a.pay,COUNT(*) AS sl FROM TABLE_TEST a
where
a.ID=1
GROUP BY
a.ORGNAME,a.pay
HAVING
COUNT(*)=1
union all
SELECT b.ORGNAME,b.pay,COUNT(*) AS sl FROM TABLE_TEST b
where
b.ID=2
GROUP BY
b.ORGNAME,b.pay
HAVING
COUNT(*)=1) aa,TABLE_TEST aaa where aa.ORGNAME=aaa.ORGNAME and aa.pay=aaa.PAY
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询