菜鸟 求一查询语句

lcw321 2006-11-02 09:20:20
table_a(a b c)
dd -1 30
dd 1 30
ff 3 40
ee -2 20
ee 2 20
......................

我想得到table_a中没有成对出现的ff的这一行数据
...全文
153 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
lcw321 2006-11-02
  • 打赏
  • 举报
回复
郁闷给不了分啊,提示与给的分值不对,可是明明是对的啊,不过

该问题的总分值:20 
现在可给的分值:NaN


现在可给的分值:NaN  NaN好象不对了哦?
xshsoft 2006-11-02
  • 打赏
  • 举报
回复
同意 树上的鸟儿
lcw321 2006-11-02
  • 打赏
  • 举报
回复
怎么你们这么牛呢
早起晚睡 2006-11-02
  • 打赏
  • 举报
回复
来晚了
xshsoft 2006-11-02
  • 打赏
  • 举报
回复
哦.原来是这样.
chuifengde 2006-11-02
  • 打赏
  • 举报
回复
select * from table_a g where not exists(select 1 from table_a where a=g.a and b=-g.b)
dulei115 2006-11-02
  • 打赏
  • 举报
回复
select a.*
from table_a a left join table_b b on a.a = b.a and a.b = -b.b and a.c = b.c
where b.a is null
lcw321 2006-11-02
  • 打赏
  • 举报
回复
抱歉了,我这个数据中可能有
table_a(a b c)
dd -1 30
dd 1 30
ff 3 40
ee -2 20
ee 2 20
dd -1 30
dd 1 30
ff -4 40

......................

也就是说可能重复出现"对"(dd) 以及重复出现的 单一记录 (ff)
要的记录是
ff 3 40
ff -4 40

xshsoft 2006-11-02
  • 打赏
  • 举报
回复
CREATE TABLE table_a
(
a CHAR(2),
b INT,
c INT
)
GO
INSERT INTO table_a
SELECT 'dd', -1, 30 UNION ALL
SELECT 'dd', 1, 30 UNION ALL
SELECT 'ff', 3, 40 UNION ALL
SELECT 'ee', -2, 20 UNION ALL
SELECT 'ee', 2, 20 UNION ALL
SELECT 'cc', 2, 40
GO
SELECT table_a.*
FROM table_a,(SELECT a FROM table_a GROUP BY a HAVING COUNT(a)<2) b
WHERE
table_a.a=b.a
GO
DROP TABLE table_a
dulei115 2006-11-02
  • 打赏
  • 举报
回复
select a.*
from table_a a left join table_b b on a.a = b.a and a.b = -b.b and a.c = b.c
where b.a is null
chenjunjarysky 2006-11-02
  • 打赏
  • 举报
回复
select a.* from table_a a,(select a from table_a group by a having count(*)=1) as t
where a.a=t.a
marco08 2006-11-02
  • 打赏
  • 举报
回复
select a from table_a group by a having count(a)>1
dawugui 2006-11-02
  • 打赏
  • 举报
回复
select * from table_a as m,
(select a , count(*) from table_a group by a having count(*) < 2) n
where m.a = n.a
chuifengde 2006-11-02
  • 打赏
  • 举报
回复
select * from table_a where a in(select a from table_a group by a having count(1)=1)
CSDMN 2006-11-02
  • 打赏
  • 举报
回复
select a.* from table_a a,(select a from table_a group by a having count(*)=1) as t
where a.a=t.a

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧