How do I get fuzzy search in selectSUM sum? $ SQL = "select username, SUM (IF (types = 1, smoney, 0) as t1 from record where 1 = 1". $ s1. "GROUP BY username ";
The result is as follows: the sum of the smoney fields of the types field = 1 of username = username in the record table is assigned the variable $ t1.
I want to change the query condition
Expected result: the sum of the smoney fields in username = username and regfrom fields that contain the types field = 1 of nameuser in the record table is assigned the variable $ t1.
How can I write an SQL statement. Database:
Reply to discussion (solution)
TheWhat does that mean?
For example, you can query the admin information in the nameuser field.
$ Username = $ _ REQUEST ['username'];
Example:
The query User is admin.
The username field is medium to admin.
And the regfrom field that contains the admin
The result is: 10 + 10 + 20 + 30 + 20
The query User is b123456.
The username field is medium to b123456
And regfrom fields that contain b123456
The result is: 20 + 30 + 20.
$username=$_REQUEST['username'];$sql="select username, SUM(smoney) as t1 from record where username='$usename'";
Does the regfrom field contain $ usename?
Isn't it enough to add the conditions?
Does the regfrom field contain $ usename?
In a word, there is no such thing.
$sql="select username, SUM(smoney) as t1 from record where username='$usename' or instr(regfrom, '$username') >0";