显示在Grafana中逗号分开的列值
我有一个包含 2 列的表,
organization_id | user_name
1 | abc
1 | xyz
2 | bhi
2 | ipq
2 | sko
3 | ask
...
每个组织可以拥有任意数量的用户,范围从 1 到 100、2000 等。 我想在 grafana 中的表格中显示它们,如下所示:
organization_id | user_name
1 | abc, xyz
2 | bhi, ipq, sko
3 | ask
由于可能有很多用户,我想显示属于同一组织的任意 10 个用户。
这里的数据库是timescale db,该表也是一个时间序列表,显示用户何时注册
I have a table with 2 columns
organization_id | user_name
1 | abc
1 | xyz
2 | bhi
2 | ipq
2 | sko
3 | ask
...
Each organization could have any number of users ranging from 1 to 100, 2000 and so on.
I wanted to show them in grafana in a table as following:
organization_id | user_name
1 | abc, xyz
2 | bhi, ipq, sko
3 | ask
Since there could be many users I want to show any 10 users belonging to same organization.
The database here is timescale db, the table is also a time series table showing when user was registered
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您希望每个组织有 10 个用户,您可以使用下面的查询。
我在 CTE 中添加了 group by 以避免返回重复的用户名。
在测试架构中,组织 2 存在重复的“pqr”值,但该用户名仅返回一次,即使 2 的用户名少于 10 个
测试架构 db Fiddle 此处
另一种可能有用的替代方案。如果删除 where 并将以下内容放在
From topTen
之后,您将获得所有不同的用户名,每行 10 个。db<>fiddle 此处
If I understand rightly that you want 10 users per organisation you can use the query below.
I have added group by in the CTE to avoid returning duplicate user_name's.
In the test schema there are duplicate values of 'pqr' for organisation 2 but this username is only returned once even though there are less then 10 user_name's for 2
test schema db Fiddle here
Another alternative which may be useful. If you remove the where and put the following after
From topTen
you will get all the distinct user_names, 10 per row.db<>fiddle here