同样一条语句,不同写法效率高10倍


#查询自2010-12-12011-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-12011-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)
posted @ 2011-03-08 20:37  小伍BLOG  阅读(263)  评论(0编辑  收藏  举报