$sql = "Select Username,sum (IF (types = 1, Smoney, 0)) as T1 from record where 1=1". $s 1. " GROUP by username ";
The result now is that the sum of the Smoney fields of username = Username in the record table = 1 is assigned a variable $t 1
I'd like to change the query criteria
Hopefully the result is: the sum of the types field in the Record table username = username and the Smoney field with Nameuser in the Regfrom field = 1 is assigned a variable $t 1
How to write the SQL statement. Database:
Reply to discussion (solution)
What does it mean to contain nameuser ?
For example, user admin query query to nameuser This field of the admin information
$username =$_request[' username '];
Cases:
Query user for Admin
The username field equals admin
And the Regfrom field that contains the admin
The result is: 10+10+20+30+20
Query user for b123456
The username field equals b123456
And the Regfrom field that contains the b123456
The result is: 20+30+20
$username =$_request[' username '); $sql = "Select Username, SUM (Smoney) as T1 from record where username= ' $usename '";
Do you want to include $usename in the Regfrom field?
Can you just add the conditions?
Do you want to include $usename in the Regfrom field?
Extrapolate a little bit.
$sql = "Select Username, SUM (Smoney) as T1 from record where username= ' $usename ' or InStr (Regfrom, ' $username ') >0";