w表结构:
cid output base base2 base3
1 15 22 50.09 -5
2 99 20.01 9 44.89
希望一次得到这样的结果
对cid=1这条记录而言:
1 15 67.09
即查询是这条样的
select cid,output,sum(base1+base2+base3) from w where cid='1'
可这样写是不对的,请大家帮忙,谢谢.....
cid output base base2 base3
1 15 22 50.09 -5
2 99 20.01 9 44.89
希望一次得到这样的结果
对cid=1这条记录而言:
1 15 67.09
即查询是这条样的
select cid,output,sum(base1+base2+base3) from w where cid='1'
可这样写是不对的,请大家帮忙,谢谢.....
也不对,提示,未发现列名,经确认是“fff”不能作为列名用
select cid,output, (base1+base2+base3) as fff from w where cid='1'
where cid='1'
有多个纪录,就需要group by 了
或者select cid,sum(base1+base2+base3) from w
where cid='1'
group by cid
select cid,max(output),sum(base1+base2+base3) from w where cid='1'