gpt4 book ai didi

MySQL - 千位分隔符

转载 作者:IT老高 更新时间:2023-10-29 00:00:10 29 4
gpt4 key购买 nike

我想知道是否有办法在 SQL 查询中获取千位分隔符?

因为我有点懒惰,所以我想构建一个请求,允许我将结果复制/粘贴给我的老板,而无需添加此分隔符:D

请求看起来像这样:

SELECT  COALESCE(Customer, 'TOTAL') AS "Customer", CONCAT( COUNT( SegmentId ) , ' bookings' ) AS "Nb bookings", CONCAT( REPLACE( SUM( Price ) , '.', ',' ) , ' €' ) AS "Total (€)", CONCAT( ROUND( (
SUM( Price ) / (
SELECT SUM( Price )
FROM my_db
WHERE CreationDate = CURRENT_DATE( )
AND SegmentStatus = "OK" ) *100 ) , 2 ) , ' %'
) AS "PDM"
FROM my_db
WHERE CreationDate = CURRENT_DATE( )
AND SegmentStatus = "OK"
GROUP BY Customer
WITH ROLLUP

目前,结果是(带有';'分隔符的表格,抱歉我没能用这个编辑器制作表格:( ) :

Customer;Nb bookings;Total (€);PDM

cust_1;20 bookings;20000 €;10,01 %

cust_2;254 bookings;17852,12 €;8,12 %

我想要的是这样的结果:

Customer;Nb bookings;Total (€);PDM

cust_1;20 bookings;20 000 €;10,01 %

cust_2;254 bookings;17 852,12 €;8,12 %

有办法吗?

谢谢,
B

最佳答案

我不知道如何用空格来做到这一点,但标准(用点或逗号 [德国即])分隔可以用 FORMAT() 实现。

看看 Format Function

mysql> SELECT FORMAT(12332.123456, 4);
-> '12,332.1235'
mysql> SELECT FORMAT(12332.1,4);
-> '12,332.1000'
mysql> SELECT FORMAT(12332.2,0);
-> '12,332'
mysql> SELECT FORMAT(12332.2,2,'de_DE');
-> '12.332,20'
mysql> SELECT FORMAT(12332.2,2,'pt_BR');
-> '12332,20'

关于MySQL - 千位分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6611362/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com