Select sum sum with fuzzy query How do I get it?

Source: Internet
Author: User
$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";
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.