同样一条语句,不同写法效率高10倍
#查询自2010-12-1 到 2011-2-28延期三天以上没有发货
SELECT DISTINCT user_id
FROM order_info
WHERE order_id IN
(
SELECT order_id FROM shipping_package
WHERE add_time < shipping_time
OR shipping_status = 0
)
AND add_time >= (UNIX_TIMESTAMP('2010-12-01 00:00:00')-28800)
AND add_time <= (UNIX_TIMESTAMP('2011-02-28 23:59:59')-28800)
#查询自2010-12-1 到 2011-2-28延期三天以上没有发货 效率高的写法
SELECT DISTINCT oi.user_id
FROM order_info oi
RIGHT JOIN
(
SELECT order_id FROM shipping_package
WHERE add_time < shipping_time
OR shipping_status = 0
) AS bb ON bb.order_id=oi.order_id
WHERE
add_time >= (UNIX_TIMESTAMP('2010-12-01 00:00:00')-28800)
AND add_time <= (UNIX_TIMESTAMP('2011-02-28 23:59:59')-28800)
转载保留链接