如果增加和减少数量,我如何计算数量?
sql语句
SELECT SUM(product_stock_quantity) AS total From product_stock GROUP BY product_stock_status
我想结果是
总计100-50 = 50
如果增加和减少数量,我不知道多行记录时的数量。请帮助我。
答案 0 :(得分:0)
如果你想要总和:
button {
padding: 10px;
width: auto;
max-width: 30px;
overflow:hidden;
transition: max-width 400ms ease-in-out;
-webkit-transition: max-width 400ms ease-in-out;
-moz-transition: max-width 400ms ease-in-out;
}
button:hover {
max-width: 100%;
}
答案 1 :(得分:0)
通常情况下,您会将股票存储为负数,但是对于存储它的方式,您可以执行此操作。
SELECT SUM(CASE WHEN product_stock_status = '-' THEN -1 * product_stock_quantity ELSE product_stock_quantity) AS total From product_stock GROUP BY product_stock_status