Comparison of the two types of SQL statements and comparison of the two types of SQL statements

Source: Internet
Author: User

Comparison of the two types of SQL statements and comparison of the two types of SQL statements
SUM (p. payable-p. single_price) AS profitCount,
M. order_id AS orderId,
M. create_time,
M. dept_airport_code,
M. arrv_airport_code,
M. payable AS price
FROM
Om_passenger p,
Om_order m
WHERE
P. order_id = m. order_id
AND p. ticket_status = '1'
AND m. create_type = 3
AND m. order_status = '20140901'
GROUP
P. order_id
ORDER
M. create_time DESC;

**************************************** **************************
SELECT
SUM (p. payable-p. single_price) AS profitCount,
M. order_id AS orderId,
M. create_time,
M. dept_airport_code,
M. arrv_airport_code,
M. payable AS price
FROM
Om_passenger p,
(
SELECT
*
FROM
Om_order t
WHERE
T. create_type = 3
AND t. order_status = '20140901'
) AS m
WHERE
P. order_id = m. order_id
AND p. ticket_status = '1'
GROUP
M. order_id
ORDER

M. create_time DES


The differences between the two SQL statements are as follows: 1. Join the SQL statement first and then query it in a unified manner; 2. Join the SQL statement after query and then query it at the end. In general, the former one is more efficient, the latter is slower.

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.