我想知道是否有办法在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 %
有办法吗?
感谢,
乙
答案 0 :(得分:26)
我不知道如何使用空格,但可以使用FORMAT()
来实现标准(带点或逗号[德国])分离。
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'