我想求表中某一行的3个字段加和如有表A
表A:
字段1 字段2 字段3 字段4 字段5 字段6
3 3 3 3 3 3
2 2 2 1 5 4
我想用一条语句打印出第二行的内容并让后3个字段的加和也拿出来
[b]问题补充:[/b]
如果我的字段4、5和6都是以String型保存的 字段不能改怎么做
[code="java"]
select * , 字段4 + 字段5 + 字段6 as total from 表A where 字段1 = 2
select *,concat(字段4, 字段5, 字段6 ) as total from 表A where 字段1 = 2 [/code]
mysql下测试通过。。。
第一种是字符串相加,得数字,未数字字符串默认转成0
第二种是字符串相加变长字符串
[code="sql"]select * , 字段4 + 字段5 + 字段6 as total where 字段1 = 2[/code]