- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
行:客户 - 3,000 行位置代码 - 40,000 行卡片库存警报 - 11,000 行:cardbatch - 9,000,000 行
以下查询花费的时间超过 2 分钟。
SELECT cia.cia_orderamount,
cia.cia_notes,
cia.cia_mincount,
cia.cia_customerid,
cia.cia_id,
cia.cia_locationid,
lc.locationcode,
T1.instock,
c.id AS customerid,
c.customer
FROM cardinventoryalerts cia
INNER JOIN customers c ON cia.cia_customerid = c.id
AND c.useautocardorder = 1
INNER JOIN locationcodes lc ON cia.cia_locationid = lc.id
LEFT JOIN
(SELECT cb.customer,
CASE
WHEN cb.locationcode IS NULL
OR cb.locationcode = '' THEN NULL
ELSE cb.locationcode
END AS locationcode,
sum(CASE WHEN cb.issued = 'no' THEN 1 ELSE 0 END) AS instock
FROM cardbatch cb
GROUP BY cb.customer,
cb.locationcode ) AS T1 ON lc.locationcode = T1.locationcode
AND T1.customer = c.customer
WHERE (cia_mincount > T1.instock
OR T1.instock IS NULL)
UNION
SELECT cia.cia_orderamount,
cia.cia_notes,
cia.cia_mincount,
cia.cia_customerid,
cia.cia_id,
-1,
NULL,
T1.instock,
c.id AS customerid,
c.customer
FROM cardinventoryalerts cia
INNER JOIN customers c ON cia.cia_customerid = c.id
AND c.useautocardorder = 1
LEFT JOIN
(SELECT cb.customer,
-1,
sum(CASE WHEN cb.issued = 'no' THEN 1 ELSE 0 END) AS instock
FROM cardbatch cb
WHERE cb.locationcode IS NULL
OR cb.locationcode = ''
GROUP BY cb.customer ) AS T1 ON c.customer = T1.customer
WHERE (cia_mincount > T1.instock
OR T1.instock IS NULL)
AND cia.cia_locationid IS NULL
我尝试避免使用 UNION 以提高查询性能。所以我使用了下面的Left Join,但它运行了超过2分钟,因为Cardbatch包含更多行。
SELECT cia.cia_orderamount,
cia.cia_notes,
cia.cia_mincount,
cia.cia_customerid,
cia.cia_id,
COALESCE(cia.cia_locationid,-1),
COALESCE(lc.locationcode,NULL),
T1.instock,
c.id AS customerid,
c.customer
FROM cardinventoryalerts cia
INNER JOIN customers c ON cia.cia_customerid = c.id
AND c.useautocardorder = 1
LEFT JOIN locationcodes lc ON cia.cia_locationid = lc.id
LEFT JOIN
(SELECT cb.customer,
CASE
WHEN cb.locationcode IS NULL
OR cb.locationcode = '' THEN NULL
ELSE cb.locationcode
END AS locationcode,
sum(CASE WHEN cb.issued = 'no' THEN 1 ELSE 0 END) AS instock
FROM cardbatch cb
GROUP BY cb.customer,
cb.locationcode ) AS T1 ON lc.locationcode = T1.locationcode
AND T1.customer = c.customer
LEFT JOIN
(SELECT cb.customer,
-1,
sum(CASE WHEN cb.issued = 'no' THEN 1 ELSE 0 END) AS instock
FROM cardbatch cb
WHERE cb.locationcode IS NULL
OR cb.locationcode = ''
GROUP BY cb.customer ) AS T2 ON c.customer = T2.customer
WHERE (cia_mincount > T1.instock
OR T1.instock IS NULL)
OR ((cia_mincount > T2.instock
OR T2.instock IS NULL)
AND cia.cia_locationid IS NULL)
现在我正在尝试这种方法,请让我知道这会很好用。
CREATE TABLE `cardbatchtemp` ( `customer` varchar(100) DEFAULT NULL, `locationcode` varchar(50) DEFAULT NULL, `instock` int(11) DEFAULT NULL , KEY `cardnumber_customer` (`customer`,`locationcode`) );
INSERT INTO `cardbatchtemp`
SELECT cb.customer,
COALESCE(cb.locationcode,' '),
sum(CASE WHEN cb.issued = 'no' THEN 1 ELSE 0 END) AS instock
FROM cardbatch cb
GROUP BY cb.customer,
COALESCE(cb.locationcode,' ');
SELECT cia.cia_orderamount,
cia.cia_notes,
cia.cia_mincount,
cia.cia_customerid,
COALESCE(cia.cia_id,-1),
COALESCE(cia.cia_locationid,NULL),
lc.locationcode,
cb.instock,
c.id AS customerid,
c.customer
FROM cardinventoryalerts cia
INNER JOIN customers c ON cia.cia_customerid = c.id
AND c.useautocardorder = 1
LEFT JOIN locationcodes lc ON cia.cia_locationid = lc.id
LEFT JOIN cardbatchtemp cb ON (lc.locationcode = cb.locationcode
OR cb.locationcode IS NULL)
AND (cb.customer = c.customer)
WHERE (cia_mincount > cb.instock
OR cb.instock IS NULL)
请指教。
最佳答案
在左连接查询中添加WHERE cb.issued = 'no'
并将其替换为count以减少处理的记录数量
SELECT cb.customer,
CASE
WHEN cb.locationcode IS NULL
OR cb.locationcode = '' THEN NULL
ELSE cb.locationcode
END AS locationcode,
count(cb.issued) AS instock
FROM cardbatch cb
WHERE cb.issued = 'no'
GROUP BY cb.customer,
cb.locationcode
关于mysql - 请根据提到的行数告诉我哪个查询是有效的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23127344/
client.on('message', message => { if (message.content === `L!hug`) { if (!message.menti
我往往会忘记我 stash 了一些更改。当存储空间不为空时,我希望看到 git status 输出中提到的存储空间。有没有办法让 git status 这样做? 最佳答案 This is now a
[object Object] 是 JavaScript 对象的默认字符串表示。 如果只是 [Object] 或 [object] 我会理解,但为什么是 [object Object]?为什么第一个单
Jython 可以在这里提供帮助吗?我应该在 Jython 之上运行 Grails,如果是,如何运行?不知何故,我应该能够在同一个 JVM 上运行 Grails 和 Python 脚本。还有其他可能性
http://download.oracle.com/javase/tutorial/collections/interfaces/set.html 为什么Set接口(interface)会列出Col
我正在使用 keras 编写一个 ner 模型,并将模型部署到tensorflow-serving。然后使用http请求来获取预测结果。 这是我的代码: EMBEDDING_OUT_DIM = 128
我是一名优秀的程序员,十分优秀!