如何在PostgreSQL中显示货币值

时间:2018-10-20 04:14:21

标签: database postgresql types currency

我的数据库查询在下面,但是我仍然无法正确显示货币值。请帮助我。

launch

我的问题是出现此错误:

SELECT  SUM (orders.quantity * products.price) as total,
to_char((orders.quantity * products.price), '$99,999,999.99') AS money
    FROM
       orders
       inner join products on products.id = orders.products_id
       inner join customers on customers.id = orders.customers_id
    WHERE order_date BETWEEN CURRENT_DATE - INTERVAL '30 days'
      AND CURRENT_DATE + INTERVAL '1 days';

1 个答案:

答案 0 :(得分:0)

您并未真正说出问题所在,但是如果您使用FM格式修饰符,如

SELECT to_char(12345.67, '$99,999,999.99FM');

  to_char   
------------
 $12,345.67
(1 row)

结果可能更符合您的喜好。

要使查询正常运行,请在末尾添加一个GROUP BY子句,如

... GROUP BY money