本帖最后由 hackol 于 2014-05-12 23:39:33 编辑 $sql=select username,sum(if(types = 1, smoney, 0)) as t1 from record where 1=1.$s1. group by username;
现在得出的结果是:record 表中username = username的 types 字段 = 1 的 smoney 字段的总和 被赋值为变量 $t1
我想换一个查询条件
希望得出结果是:record 表中username = username的 以及 regfrom 字段中包含 nameuser 的 types 字段 = 1 的 smoney 字段的总和 被赋值为变量 $t1
请问sql语句该怎么写。数据库截图:
------解决方案--------------------
$sql=select username, sum(smoney) as t1 from record where username='$usename' or instr(regfrom, '$username') >0;
