Mysql-MYSQL statement optimization, online, etc.

Source: Internet
Author: User
SELECTtt.int _ interpreting_data_id, tt. dt_report_date, tn. str_norm_number, tnt. str_norm_type_name, tt.int _ whether, tt. str_value, tt. str_detection_result, tt. str_remark, tn. str_name, tn.int _ response_type, tt. str_device_name, tt. str_ip, tt. db_name, tn. str_codeF... mysql

SELECT tt.int _ interpreting_data_id, tt. dt_report_date, tn. str_norm_number, tnt. str_norm_type_name, tt.int _ whether, tt. str_value, tt. str_detection_result, tt. str_remark, tn. str_name, tn.int _ response_type, tt. str_device_name, tt. str_ip, tt. db_name, tn. str_code
FROM t_norm tn LEFT JOIN
(
SELECT Region _ code, tid1.int _ partition, region _ report_date, tid1.str _ norm_type_name, tid1.int _ whether, tid1.str _ value, tid1.str _ partition, tid1.str _ remark, tid1.str _ device_name, tid1.str _ ip, tid1.db _ name, tid1.str _ norm_number FROM t_interpreting_data tid1,
(
SELECT str_code, comment, str_norm_type_name, int_whether, str_value, comment, str_remark, str_device_name, str_ip, db_name, str_norm_number, max (dt_report_date) max_date FROM comment WHERE 1 = 1
AND str_property_id = 'windows 7_852'
AND STR_TO_DATE (dt_report_date, '% Y-% m-% d') = '2017-06-05'
Group by str_norm_number, db_name
) Tid2
WHERE tid1.dt _ report_date = tid2.max _ date
Group by tid1.str _ norm_number, tid1.db _ name
Order by tid1.dt _ report_date DESC
) Tt on tn. str_norm_number = tt. str_norm_number
Left join t_norm_type tnt ON tn.int _ norm_type_id = tnt.int _ norm_type_id
WHERE tn. str_code IN (SELECT str_code FROM t_interpreting_data WHERE str_property_id = 'windows 7_852 'group by str_code)
Order by tt. str_norm_number DESC

1. use the t_norm table as the standard
2. query the latest records of the same type in the t_interpreting_data table, and group the records according to db_name.

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.