Sql 同一表中 同字段相加 大于 100 的所有数据 !求解解决方案
Sql 同一表中 同字段相加 大于 100 的所有数据 !求解
如:
字段1 字段2 字段3
赵民 70 1
赵三 50 1
小王 50 2
条件:
字段3=1 and 字段2相加 >20
正确返回:
字段1 字段2 字段3
赵民 70 1
赵三 50 1
想了半天 都没想出来 求解 谢谢
------解决思路----------------------
这个效果?
如:
字段1 字段2 字段3
赵民 70 1
赵三 50 1
小王 50 2
条件:
字段3=1 and 字段2相加 >20
正确返回:
字段1 字段2 字段3
赵民 70 1
赵三 50 1
想了半天 都没想出来 求解 谢谢
------解决思路----------------------
这个效果?
with table1 as
(
select '赵民' col1, 70 col2, 1 col3 union all
select '赵三' col1, 50 col2, 1 col3 union all
select '小王' col1, 50 col2, 2 col3
)
select * from table1 where col3 in (select col3 from table1 where col3=1 group by col3 having SUM(col2)>20)