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 = '203'
GROUP BY
p.order_id
ORDER BY
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 = '203'
) AS m
WHERE
p.order_id = m.order_id
AND p.ticket_status = '1'
GROUP BY
m.order_id
ORDER BY
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 = '203'
GROUP BY
p.order_id
ORDER BY
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 = '203'
) AS m
WHERE
p.order_id = m.order_id
AND p.ticket_status = '1'
GROUP BY
m.order_id
ORDER BY
m.create_time DES
以上两种sql的写法的区别是: 1,先关联后统一查询 ; 2,现查询后关联然后最后查询 ; 综合情况下,前一种的效率高一点,后一种的慢一点。