MySQL Basic Query

Source: Internet
Author: User

June results List

Rank Partner performance sign interview daily goals
1 Du Yan Flower 12367 2 0 View Target
2 Zhengdongjie 2345 1 0 View Target
3 Huang 345 1 1 View Target
4 Test 0 0 0 View Target
5 Li Xia 0 0 0 View Target
6 Wang Ke 0 0 1 View Target
7 Shuang 0 0 0 View Target

When I get the above business requirements, I immediately think about how the SQL statement should be written.

Try a simple table left and right link query to join right join, obviously the problem is not so simple, data query error, and then get Big Bird guidance, recorded.

Select A.yyry_xiaotxiang, A.YYRY_ID,A.YYRY_XMING,C.CC,D.DD, B.BB
From Yyry A
Left JOIN (SELECT COUNT (mtjl_id) Bb,mtjl_yyryid
From MTJL
Where year (now ()) =year (Mtjl_yysjian) and Month (now ()) =month (Mtjl_yysjian)
Group BY Mtjl_yyryid) b on A.yyry_id=b.mtjl_yyryid
Left JOIN (select Xiaoshouid,sum (Khsh_yji) cc from KHSHDJB
Where year (now ()) =year (Khsh_jrusjian) and Month (now ()) =month (Khsh_jrusjian) GROUP BY
XIAOSHOUID) C
On A.yyry_id=c.xiaoshouid
Left JOIN (SELECT COUNT (khsh_id) dd,xiaoshouid
From KHSHDJB
Where year (now ()) =year (Khsh_jrusjian) and Month (now ()) =month (Khsh_jrusjian)
Group by Xiaoshouid) d on a.yyry_id=d.xiaoshouid where A.yyry_jsemcheng = ' transfer ' and a.yyry_id > 0 ORDER BY c.cc Desc

This is a three-table search, respectively, the Yyry (operator's table) of the image, ID, name, KHSHDJB (customer after-sales registration form) operators of the monthly results of the total, the number of orders, MTJL (interview record table) operators of the month total number of interviews.


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.