高分求一句SQL

来源:百度知道 编辑:UC知道 时间:2024/07/02 03:31:53
执行查询表如下
A B
1 3
1
1 4
1 8
2 4
2 8
3 7
3 3

查询结果为ID 为1 的,在B 中不存在空值,且最大值大于6 的 ID

查询结果:
A
2
3
上面写的有点问题
查询 表中 B字段不为空值,且A的值相同 时 B的最大值小于等于7 的 A 的值
A=1 时, B 中有空值 ,淘汰
A=2 时, B 中无空值,最大值为8>6 成立
A=3 时, B 中无空值,最大值为7>6 成立

查询结果:
A
3

不知道这样说,大家明白不~谢谢帮忙了~
谢谢4,5楼! 我的难点是最大值再比较的问题上,上面的这个如何写!
追加100分~~~~~

select A from TableName
where A not in (select distinct A from TableName where B is null)
group by A
having max(B) > 6

select id,max(b) from @table where id not in(select id from @table where isnull(b,'')='') and isnull(b,0)>6 group by id

不为空的条件是 is not null
多条件就是 Is Not Null And ID > 6

不过你的问题确实没有看懂

确实不明,

select distinct A from 表 where B>6

确实不明

select distinct A from 表 where B>6 and A not in(select distinct A from 表 where B is not null)
是着样吗?