MYSQL,在工作台中为具有十进制(M,D)的列创建新查询

时间:2018-02-20 10:21:37

标签: mysql database mysql-workbench

目前,我正在为销售到达国家的每个国家/地区开展增值税工作。

这个增值税运作良好且正确,但是,我遇到了0.0000000的问题,因为我尝试将合并与0.00一起但是它仍然显示在' 3632.608266'而不是' 3632.60'我正在寻找

这是我写的MySQL查询

SUM(COALESCE((TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)-(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)/(VAT_Standard_Rate + 1),0.00)) AS 'decmical',

这是完整版

SELECT 
    SALE_ARRIVAL_COUNTRY,
    tbl_countries.Country,
    VAT_Standard_Rate,
    SUM(COALESCE((TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)-(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)/(VAT_Standard_Rate + 1),0.00)) AS 'decmical',
    SUM(COALESCE(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)+(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)/(VAT_Standard_Rate + 1)-(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)) AS 'NET',
    SUM(COALESCE(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)-(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)/(VAT_Standard_Rate + 1)) AS 'VAT',
    SUM(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL) AS 'Total',
    TRANSACTION_CURRENCY_CODE as 'Currency'
FROM
    tbl_vat
INNER JOIN tbl_countries
INNER JOIN tbl_vat_rate
ON amazon.tbl_vat.SALE_ARRIVAL_COUNTRY=tbl_countries.alpha_2 AND tbl_countries.Country=tbl_vat_rate.Country_of_Purchase
GROUP BY tbl_countries.Country

以下是黄色突出显示的结果屏幕截图 enter image description here

2 个答案:

答案 0 :(得分:1)

您可以使用SQL中的格式函数:

FORMAT(SUM(COALESCE((TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)-(TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL)/(VAT_Standard_Rate + 1),0.00)), 2) AS 'decmical',

答案 1 :(得分:1)

您可以使用Round()函数

ROUND(N,[D])
ROUND() rounds a number specified as an argument up 
to a number specified as another argument.
像这样:

mysql> SELECT ROUND(-4.535,2);
+-----------------+
| ROUND(-4.535,2) |
+-----------------+
|           -4.54 | 
+-----------------+
1 row in set (0.00 sec)

OR

您可以使用截断功能

TRUNCATE(X,D)
Returns the number X, truncated to D decimal places
像这样:

mysql> SELECT TRUNCATE(1.223,1);
    -> 1.2
mysql> SELECT TRUNCATE(1.999,1);
    -> 1.9