我使用以下SQL创建具有值的表:
CREATE TABLE Logistics (
country TEXT,
Costs_Inbound CHAR(255),
Costs_Storage CHAR(255),
Costs_Outbound DECIMAL(65,3)
);
INSERT INTO Logistics
(country, Costs_Inbound, Costs_Storage, Costs_Outbound)
VALUES
("DE", "5000", "300", "600500.815"),
("NL", "3000", "650", "250452.454"),
("FR", "4000", "120", "750060.932");
以及以下SQL从表中查询值:
SELECT country, sum(Costs_Inbound), sum(Costs_Storage), sum(Costs_Outbound),
(sum(Costs_Inbound) + sum(Costs_Storage) + sum(Costs_Outbound)) as Total
FROM Logistics
GROUP BY country WITH ROLLUP;
您也可以在
sqlfiddle
here中找到代码。到目前为止,所有这些工作正常。
现在,我希望这些值使用千位分隔符进入表中,因此它们应显示为
6000500,815
,250452.454
和750060.932
,而不是600,500.815
,250,452.454
和750,060.932
。你有什么想法我能做到吗?
最佳答案
使用format
功能
SELECT country, FORMAT (sum(Costs_Inbound),2) Costs_Inbound,
FORMAT(sum(Costs_Storage),2) Costs_Storage,
FORMAT(sum(Costs_Outbound), 2) Costs_Outbound,
FORMAT( (sum(Costs_Inbound) + sum(Costs_Storage) + sum(Costs_Outbound)),2) as Total
FROM Logistics
GROUP BY country WITH ROLLUP
http://sqlfiddle.com/#!9/92d35b2/7
关于mysql - 将带有千位分隔符的值插入表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51872723/