MySQL case where & concat & Substring_index & not & have used small case

Source: Internet
Author: User

1. Code

SELECT a.id, A.activity_name, ( case when A.activity_end_time>Now () Then' Participation 'ELSE (A.activity_doubt<> ' * 'and A.activity_doubt<c.doubt) OR (a.activity_praise<> ' * 'and a.activity_praise> c.praise * 100) Then' Not compliant 'ELSE' Standards 'END)            END) as state, c.driver_id, C.driver_phone, C.driver_name, C.countfrom (SELECT ID,                Activity_name, Activity_end_time, Substring_index (Driver_award_condition, "-",                1) as Activity_doubt, Substring_index (Driver_award_condition, "-",                -1) as activity_praise from Car_biz_numprize_base as B WHERE1 = 1and activity_name like Concat (Concat ('% ', ' data '), '% ') and ID= 1And not ((Activity_start_time> ' 2017-10-27 17:16:00 ') OR (Activity_end_time< ' 2017-10-27 17:10:00 ')) as Ainner JOIN (SELECT i.driver_id, I.driver_phone, I.driver_name , i.numprize_base_id, COUNT (order_no) as Count, sum (ORDER_DOUBT) as doubt, SUM (order_praise) /c0>/count (Order_no) as praise from Car_biz_numprize_order_item I WHERE1 = 1and driver_id= 1000063GROUP by i.driver_id, i.numprize_base_id) As C on a.ID=c.numprize_base_idhaving State= ' nonconformance ' ORDER by a.created_time DESC, c.driver_id ASCLIMIT0, 10

2. Sources of demand

2.1 Compliance with the activity criteria query as shown in the following page 2-1

2.2 Event-related tables

Activity Table 2-2

Qualifying Orders Table 2-3

2.1 The query condition for the active participation status in the diagram is a field that does not exist in the two tables

You need to get the Driver_award_condition column from Activity Table 2-2 and split the criteria and then perform the operation on the 2-1 table and then choose again.

2.4 If the mybatis in the SQL is less than the greater than the number placed in the <! [CDATA [>]]> in

Select Substring_index (REVERSE (Substring_index ("Aa,bb,cc,dd", ",", 1)), ",", 1); #aa
Select Substring_index (REVERSE (Substring_index ("Aa,bb,cc,dd", ",", 2)), ",", 1); #bb
Select Substring_index (REVERSE (Substring_index ("Aa,bb,cc,dd", ",", 3)), ",", 1); #cc
Select Substring_index (REVERSE (Substring_index ("Aa,bb,cc,dd", ",", 4)), ",", 1); #dd

3. Summary

Complex SQL is written step-by-step

MySQL case when & concat & Substring_index & not & have used small case

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.