唯一值列表而不是计数 teradata sql
我有 2 列;访问方法 ID、应用程序名称 每个用户不时使用不同的应用程序,我需要编写一个查询来获取用户在一列中使用过的所有应用程序的列表。 像这样
acess_method_id | App_Name
12345 | [bima,gaming,tube]
34579 | [candy,bubbles,gaming,tube]
我运行查询的表中的数据看起来像这样
acess_method_id | App_Name
12345 | bima
12345 | gaming
12345 | tube
34579 | candy
34579 | bubbles
34579 | gaming
34579 | tube
我正在 Dbeaver 的 Teradata 上使用此查询,
Select COUNT(DISTINCT App_Name),ACCESS_METHOD_ID
from DP_VEW.mytable as a
GROUP BY ACCESS_METHOD_ID
此查询为我提供了应用程序的计数,我需要获取列表。使用 Teradata SQL 有没有办法编写查询来获得所需的结果?
I have 2 columns; access_method-id, app_name
Each user uses different apps from time to time and I need to write a query to get a list of all the apps that the user have used in one column.
like this
acess_method_id | App_Name
12345 | [bima,gaming,tube]
34579 | [candy,bubbles,gaming,tube]
Data in the table on which I am running the query looks like this
acess_method_id | App_Name
12345 | bima
12345 | gaming
12345 | tube
34579 | candy
34579 | bubbles
34579 | gaming
34579 | tube
I am using this query on Teradata from Dbeaver
Select COUNT(DISTINCT App_Name),ACCESS_METHOD_ID
from DP_VEW.mytable as a
GROUP BY ACCESS_METHOD_ID
this query gives me a count of the apps, I need to get the list. Using Teradata SQL is there a way to write a query to get the desired results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 XMLAGG()
use XMLAGG()
您想要的是类似于标准 SQL 的 ListAgg 函数,该函数在 Teradata 中未实现。
但 nPath 也可以返回这个结果。您必须习惯该语法,但它比 XMLAGG 高效得多。
您还可以将不同的值移至 RESULT 函数中,如下所示:
检查哪个版本更有效。
What you want is similar to Standard SQL's ListAgg function, which is not implemented in Teradata.
But nPath can return this result, too. You have to get used to the syntax, but it's way more efficient than XMLAGG.
You can also move the distinct into the RESULT functions like this:
Check which version is more efficient.