下面就sql多字段求和并作为sql查询条件的方法进行了说明,供您参考,希望对您学习sql查询方面有所帮助。
做一个字段求和的小sql查询,查询一个表中,字段1,字段2和字段3之和大于0的结果,故写了如下的sql语句。
有一点要注意的是,在where字句中,,不能有自己运算后得到的字段。
sqlstr = select w.id,w.weather,greencolor,(select redcolor+greencolor+bluecolor from weather n where n.id = w.id) as allvalue from weather w where (select redcolor+greencolor+bluecolor from weather n where n.id = w.id)>0 order by id;
即如下的sql语句是行不通的,说是至少一个参数没有被指定值。
sqlstr = select w.id,w.weather,greencolor,(select redcolor+greencolor+bluecolor from weather n where n.id = w.id) as allvalue from weather w where allvalue >0 order by id;