在 Postgresql 中从聚合 ID 中选择名称

发布于 2025-01-19 02:37:43 字数 927 浏览 0 评论 0原文

我不知道该怎么做。

    (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_Categorydata_countRoom_id
Room 1{25,25,25,25}4150

目标是计算出现上层类别的次数以及该类别的名称。

一切都在房间桌上,但我无法理解,只有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:

Nameupper_categorydata_countroom_id
Room 1{25,25,25,25}4150

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文