SQL问题 求指导
- iamright
ID AID BID 李四 aa 22 李四 aa1 22 王五 aa 111 王五 aa1 111 张三 aa 120 张三 aa1 100 张三 aa1 200
假如有一张类似于上面的table我想要查询 aa不等于aa1的名单 请问语句要怎么写 需要结果是张三 - iamrightaa1允许存在两条 aa只要等于其中一条即可
- 热心网友瞎说一个,弄一个select,套俩select
- songco"aa不等于aa1的名单"
我觉得你要先说清楚需求, 体育老师都不敢这么说把 - iamright
- wangbaichiselect * from table a, table B where a.id = b.id and a.aid ='aa' and b.aid = 'aa1' and a.bid<>b.bid
- quejuwen行转列
- wlzc911select * from temp a where aid='aa' and not exists(select 1 from temp b where a.id=b.id and b.aid='aa1' and a.bid=b.bid)
- deepnessselect ID from table group by ID,BID having count(*) = 1
按照这个思路试试 - ptcptr回复1#iamright
select ID from table group by id having sum(case when aid='aa' then bid else 0 end)<>sum(case when aid='aa1' then bid else 0 end) - opensesame等饭的功夫无聊的自己建了张表试试,不是可以么,如果你只要取个名字的话
- iamgs这表达能力我也是服。
- voov我更佩服楼上的,居然能看懂楼主的需求
- fang1023看不懂这需求,值不等于值?
- pluckLZ描述的意思我都看不明白,是不是该蹲到墙角去数蚂蚁了。。。
- cyberiser我有点理解我司员工老是写bug了
- zjy1993