我使用以下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
{1}},600,500.815
和250,452.454
。
您知道我如何实现这一目标吗?
答案 0 :(得分:0)
使用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