任何人都可以指导我使用Azure Data Lake中使用的U-SQL语言编写下面的SQL
select tt.userId, count(tt.userId) from (SELECT userId,count(userId) as cou
FROM [dbo].[users]
where createdTime> DATEADD(wk,-1,GETDATE())
group by userId,DATEPART(minute,createdTime)/5) tt group by tt.userId
我在U-SQL中找不到DATEPART功能。 Azure Data Analytic作业给了我错误。
答案 0 :(得分:2)
除少数(如LIKE)外,U-SQL不提供T-SQL内部函数。有关列表,请参阅The code I'm talking about is here at about line 75.。
那么你如何做DateTime操作呢?您只需使用C#函数和方法!
所以DATEADD(wk, -1, GETDATE())
就像DateTime.Now.AddDays(-7)
和
DATEPART(minute,createdTime)/5
(您的行中有一个额外的)
)类似于createdTime.Minute/5
(如果您想要非整数值,可能需要将其强制转换为double。)
答案 1 :(得分:2)
对于正在寻找Michael提到的实施的人。就像下面的
@records =
EXTRACT userId string,
createdTime DateTime
FROM "/datalake/input/data.tsv"
USING Extractors.Tsv();
@result =
SELECT
userId,
COUNT(createdTime) AS userCount
FROM @records
WHERE createdTime > DateTime.Now.AddDays(-30)
GROUP BY userId,createdTime.Minute/5;
@result2= SELECT userId,COUNT(userId) AS TotalCount
FROM @result
GROUP BY userId;
OUTPUT @result2
TO "/datalake/output/data.csv"
USING Outputters.Csv();