Home  >  Article  >  Backend Development  >  select SUM 求和中带模糊查询如何弄

select SUM 求和中带模糊查询如何弄

WBOY
WBOYOriginal
2016-06-13 11:57:091652browse

select SUM 求和中带模糊查询怎么弄?

本帖最后由 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";
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn