您好,我的 MYSQL 数据库包含名为new-sell
的表格,其中包含以下列registeredDay
和productFinalPrice
强>总 已注册购买值,日期该条目已。
|=====================================|
| productFinalPrice | registeredDay |
|=====================================|
| 600,00 | 2017-09-19 18:45:16 |
| 435,50 | 2017-09-18 18:45:16 |
| 817,60 | 2017-09-17 18:45:16 |
| 176,00 | 2017-09-16 18:45:16 |
| 600,00 | 2017-09-15 18:45:16 |
| 600,00 | 2017-09-14 18:45:16 |
| 600,00 | 2017-09-13 18:45:16 |
| 842,10 | 2017-09-20 18:45:16 |
| 415,20 | 2017-09-21 18:45:16 |
| 230,45 | 2017-09-22 18:45:16 |
| 400,00 | 2017-09-20 18:45:16 |
| 375,00 | 2017-09-20 18:45:16 |
=======================================
我使用这个 MySQL命令计算平均收入与昨天以及之前相比的昨天
SELECT PRICE_T / (PRICE_T2-PRICE_T) * 100 AS PERC
FROM (SELECT SUM(CASE WHEN RN=1 THEN PRICE_I2 ELSE 0 END) AS PRICE_T
, SUM(PRICE_I2) AS PRICE_T2
FROM (SELECT CAST(registeredDay AS DATE) AS DDATE
, SUM(productFinalPrice) AS PRICE_I2
, @RN:=@RN+1 AS RN
FROM new_sell
CROSS JOIN (SELECT @RN:=0) X
WHERE registeredDay BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 day) AND CURDATE()
GROUP BY CAST(registeredDay AS DATE)
ORDER BY CAST(registeredDay AS DATE)
) B
) C;
这是最终结果。
37,1057513914657
然而我希望 围绕这个最终值到ROUND()
我将命令 添加到以上查询?
感谢您帮助我:]
答案 0 :(得分:1)
您可以直接在您的选择中使用MySQL round()
功能。
SELECT
ROUND(PRICE_T / (PRICE_T2-PRICE_T) * 100) AS PERC
FROM (SELECT SUM(CASE WHEN RN=1 THEN PRICE_I2 ELSE 0 END) AS PRICE_T
, SUM(PRICE_I2) AS PRICE_T2
FROM (SELECT CAST(registeredDay AS DATE) AS DDATE
, SUM(productFinalPrice) AS PRICE_I2
, @RN:=@RN+1 AS RN
FROM new_sell
CROSS JOIN (SELECT @RN:=0) X
WHERE registeredDay BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 day) AND CURDATE()
GROUP BY CAST(registeredDay AS DATE)
ORDER BY CAST(registeredDay AS DATE)
) B
) C;
答案 1 :(得分:0)
使用可以使用圆内的和 - SELECT ROUND(column_name,decimals)FROM table_name;