今天上班礼拜一,没有什么事做,前一段时间比较忙,好久没有来写点东西了,回顾前几天的工作,让我记忆犹新的是一个简单而又花了我几个小时的sql现在拿出来给大家看看我有多菜咯,呵呵。。。
现在的需求是将表中point>100的id显示出来,我真的弄晕了一下:
下面一个SQL Script大家看看是不是可以优化咯。
select A.id ,sum(Point) as p from TT A where (select sum(point) pp from TT B where B.id=A.id)>100
group by id order by id Desc
id | point |
1 | 87 |
2 | 23 |
2 | 43 |
3 | 3 |
2 | 56 |
1 | 54 |
现在的需求是将表中point>100的id显示出来,我真的弄晕了一下:
下面一个SQL Script大家看看是不是可以优化咯。
select A.id ,sum(Point) as p from TT A where (select sum(point) pp from TT B where B.id=A.id)>100
group by id order by id Desc