Select sum sum with fuzzy query how to get

Source: Internet
Author: User
Select sum sum with fuzzy query How do I get it?
This post was last edited by Hackol on 2014-05-12 23:39:33

$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:
------Solution--------------------

$sql = "Select Username, SUM (Smoney) as T1 from record where username= ' $usename ' or InStr (Regfrom, ' $username ') >0";
  • Related Article

    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.