2011-07-07 218 views
11

我想知道是否有辦法在SQL查詢中獲得千位分隔符?MYSQL - 千位分隔符

因爲我有點懶,我想建立可以讓我複製/粘貼的結果對我的老闆不添加這種分離器的請求: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 % 

有沒有辦法做到這一點?

謝謝,

回答

19

我不知道如何與一個空間做,但標準(用點或逗號[德國即])分離 - 可以與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' 
+3

謝謝你,我能夠做到什麼,我想與使用REPLACE(..., ' ''')。謝謝 ! –