|
|
@@ -2030,9 +2030,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 1
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 1, MONTH ( create_time ) = 1 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI1 ON BOI1.id = BO.id
|
|
|
@@ -2044,9 +2057,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 2
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 2, MONTH ( create_time ) = 2 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI2 ON BOI2.id = BO.id
|
|
|
@@ -2058,9 +2084,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 3
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 3, MONTH ( create_time ) = 3 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI3 ON BOI3.id = BO.id
|
|
|
@@ -2072,9 +2111,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 4
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 4, MONTH ( create_time ) = 4 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI4 ON BOI4.id = BO.id
|
|
|
@@ -2086,9 +2138,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 5
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 5, MONTH ( create_time ) = 5 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI5 ON BOI5.id = BO.id
|
|
|
@@ -2100,9 +2165,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 6
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 6, MONTH ( create_time ) = 6 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI6 ON BOI6.id = BO.id
|
|
|
@@ -2114,9 +2192,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 7
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 7, MONTH ( create_time ) = 7 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI7 ON BOI7.id = BO.id
|
|
|
@@ -2128,9 +2219,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 8
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 8, MONTH ( create_time ) = 8 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI8 ON BOI8.id = BO.id
|
|
|
@@ -2142,9 +2246,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 9
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 9, MONTH ( create_time ) = 9 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI9 ON BOI9.id = BO.id
|
|
|
@@ -2156,9 +2273,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 10
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 10, MONTH ( create_time ) = 10 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI10 ON BOI10.id = BO.id
|
|
|
@@ -2170,9 +2300,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 11
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 11, MONTH ( create_time ) = 11 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI11 ON BOI11.id = BO.id
|
|
|
@@ -2184,9 +2327,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 12
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 12, MONTH ( create_time ) = 12 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI12 ON BOI12.id = BO.id
|
|
|
@@ -2260,9 +2416,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 1
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 1, MONTH ( create_time ) = 1 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI1 ON BOI1.id = BO.id
|
|
|
@@ -2274,9 +2443,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 2
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 2, MONTH ( create_time ) = 2 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI2 ON BOI2.id = BO.id
|
|
|
@@ -2288,9 +2470,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 3
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 3, MONTH ( create_time ) = 3 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI3 ON BOI3.id = BO.id
|
|
|
@@ -2302,9 +2497,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 4
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 4, MONTH ( create_time ) = 4 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI4 ON BOI4.id = BO.id
|
|
|
@@ -2316,9 +2524,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 5
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 5, MONTH ( create_time ) = 5 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI5 ON BOI5.id = BO.id
|
|
|
@@ -2330,9 +2551,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 6
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 6, MONTH ( create_time ) = 6 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI6 ON BOI6.id = BO.id
|
|
|
@@ -2344,9 +2578,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 7
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 7, MONTH ( create_time ) = 7 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI7 ON BOI7.id = BO.id
|
|
|
@@ -2358,9 +2605,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 8
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 8, MONTH ( create_time ) = 8 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI8 ON BOI8.id = BO.id
|
|
|
@@ -2372,9 +2632,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 9
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 9, MONTH ( create_time ) = 9 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI9 ON BOI9.id = BO.id
|
|
|
@@ -2386,9 +2659,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 10
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
+ WHERE
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 10, MONTH ( create_time ) = 10 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI10 ON BOI10.id = BO.id
|
|
|
@@ -2400,9 +2686,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 11
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 11, MONTH ( create_time ) = 11 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI11 ON BOI11.id = BO.id
|
|
|
@@ -2414,9 +2713,22 @@ ORDER BY
|
|
|
sum( bt.quantity ) AS quantity
|
|
|
FROM
|
|
|
business_order b
|
|
|
- LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pid,
|
|
|
+ item_id,
|
|
|
+ IF
|
|
|
+ ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
|
|
|
+ FROM
|
|
|
+ business_order_items
|
|
|
+ WHERE
|
|
|
+ is_deleted = 0
|
|
|
+ GROUP BY
|
|
|
+ pid
|
|
|
+ ) bt ON bt.pid = b.id
|
|
|
WHERE
|
|
|
- MONTH ( create_time ) = 12
|
|
|
+ IF
|
|
|
+ ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 12, MONTH ( create_time ) = 12 )
|
|
|
GROUP BY
|
|
|
b.id
|
|
|
) BOI12 ON BOI12.id = BO.id
|