sql - 如何在 PostgreSql 数据库中将双精度转换为字符串
问题描述
我想知道我如何将双精度转换为字符串,或者你是否可以做到?我正在使用的代码是:
select
(select name from locations loc where loc.type = 9 and id in (select id from locations where l.parent = loc.id)) BayName,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT l.name), ', ') TroughName,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT b.name), ', ') BatchName,
**ARRAY_TO_STRING(ARRAY_AGG(CAST(sum(case when m.type = 1 and l.name = l.name then m.amount end)-
sum(case when m.type = 3 and l.name = l.name then m.amount else 0 end)-
sum(case when m.type = 5 and l.name = l.name then m.amount else 0 end) AS varchar(200))), ', ')** MotherTotalAmount
from batches b
left outer join phases p on b.id = p.batch
left outer join movements m on b.id = m.batch
left outer join locations l on m.location = l.id
where b.type = 2 and p.type = 13 and b."isActive" = 'true' and m.type in (1, 3 , 5) and (select name from locations loc where loc.type = 9 and id in (select id from locations where l.parent = loc.id)) is not null
group by (select name from locations loc where loc.type = 9 and id in (select id from locations where l.parent = loc.id)), l.name
对于 MothersTotalAmount 字段,输出应该看起来像下面的批处理名称,而不是只给出总数
"bayname" "troughname" "batchname" "mothertotalamount"
"13N" "4" "BLW-002M, CHG-002M, GEL-002M, GJE-003M, GLU-002M, GOG-002M, GSC-002M, GTH-001M, R4-001M, SOD-002M" 89
我需要将总和作为字符串,以便具有与 ARRAY_TO_STRING(ARRAY_AGG(DISTINCT b.name), ', ') BatchName 相同的输出,除非有不同的方法吗?
解决方案
推荐阅读
- powershell - 管道流到其他进程
- slack-api - Slack API - 用户详细信息上次更新日期
- excel - 出现错误后取消隐藏隐藏 Excel 工作表并关闭用户窗体
- python - 为什么这个输出辐照度预测值会有些相同?我正在使用 PVLIB 的 GFS 模型。我在这里做错了什么?
- php - 从预先加载的 laravel 集合中加载特定的列
- acumatica - Acumatica:正确释放的正确方法是什么,以便首先发生基础
- rust - 如何使用标准库对单词进行排序?
- java - Eclipse 错误:java.lang.ClassNotFoundException:org.eclipse.e4.core.di_1.6.1.v20160712-0927 找不到 javax.annotation.PreDestroy
- php - 具有相同名称 Woocommerce 的多个属性
- c++ - 是否可以展开可变参数 (lambda) 模板并将这些函数的返回值传递给另一个可变参数函数?