在 Postgresql 中从聚合 ID 中选择名称
我不知道该怎么做。
(Select Dane1.Name, Array_agg(Dane1.UpperCat) as "upper_category", count(Dane1.UpperCat) As data_count, dane1.room_id
From
(Select
contact.room_id,
UpperCategory_Id As "UpperCat", /* uppper category ID of rooms */
Rooms.Name As "Name",
Rooms.Type
From Public.contact
Join Rooms On contact.room_id= Rooms.Rooms_Id) As Dane1
Group by Dane1.Name, Dane1.UpperCat,dane1.room_id)
结果:
名称 | Upper_Category | data_count | Room_id |
---|---|---|---|
Room 1 | {25,25,25,25} | 4 | 150 |
目标是计算出现上层类别的次数以及该类别的名称。
一切都在房间桌上,但我无法理解,只有Sub Room ID的名字。我不在乎{25,25,25,25},但是与汇总函数中该ID相对应的名称。
I have no clue how to do this.
(Select Dane1.Name, Array_agg(Dane1.UpperCat) as "upper_category", count(Dane1.UpperCat) As data_count, dane1.room_id
From
(Select
contact.room_id,
UpperCategory_Id As "UpperCat", /* uppper category ID of rooms */
Rooms.Name As "Name",
Rooms.Type
From Public.contact
Join Rooms On contact.room_id= Rooms.Rooms_Id) As Dane1
Group by Dane1.Name, Dane1.UpperCat,dane1.room_id)
Result:
Name | upper_category | data_count | room_id |
---|---|---|---|
Room 1 | {25,25,25,25} | 4 | 150 |
The goal is to count how many times the upper category occurs AND what's the name of said category.
It's all in Rooms table but I can't get that, only sub room ID's name. I don't care about {25,25,25,25} but the name that corresponds to that ID in the aggregate function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论