How do I get fuzzy search in selectSUM sum?

Source: Internet
Author: User
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";

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.