如何在查询中指定日期范围? [英] how to specify a date range in a query?

查看:107
本文介绍了如何在查询中指定日期范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个关于在查询中指定日期范围的问题.从正在运行的Log Analytics中获取以下示例:

Hi, I have a question regarding specifying a date range in a query. Take this example from Log Analytics which is working:

|延长Date = floor(timestamp,1d)
|时间戳记> = ago(100d)
|总结count()
按日期,client_OS
| orderby日期asc

这意味着:获取最近100天使用的操作系统,并按日期将其分组.
现在,我想让它在Stream Analytics中工作,但我无法使其工作.我这样尝试过,但未返回任何结果:


SELECT
p.context.device.osVersion,
System.TimeStamp作为时间,
count(*)
INTO
[pageviews-operatingsystems]
来自
[stream_analytics_input] p TIMESTAMP BY Time
日期差异(dayofyear,p.context.data.eventTime,Time)在0到100之间
GROUP BY
TumblingWindow(day,1),p.context.device.osVersion

这样的查询也不会给我任何结果:

SELECT
p.context.device.osVersion,
datediff(dayofyear,System.TimeStamp,p.context.data.eventTime)作为区别,
count(*)
INTO
[pageviews-operatingsystems]
来自
[stream_analytics_input] p
差异
< 100
GROUPBY 
TumblingWindow(day,1),p.context.device.osVersion,p.context.data.eventTime

我究竟做错了什么?我在的Stream Analytics中寻找了此内容,但找不到我想要的有效示例.提前致谢.

| extend Date = floor(timestamp,1d)
| where timestamp >= ago(100d)
| summarize count()
by Date, client_OS
| orderby Date asc

This means: get the operating systems used by last 100 days and group them by Date.
Now I wanted to get this working in Stream Analytics and I cannot get it to work. I tried it like this but it is not returning me any results:


SELECT
p.context.device.osVersion,
System.TimeStamp as Time,
count(*)
INTO
[pageviews-operatingsystems]
FROM
[stream_analytics_input] p TIMESTAMP BY Time
WHERE datediff(dayofyear, p.context.data.eventTime,Time) between 0 and 100
GROUP BY
TumblingWindow(day,1), p.context.device.osVersion

so is this query which is not giving me any results either:

SELECT
p.context.device.osVersion,
datediff(dayofyear,System.TimeStamp, p.context.data.eventTime) as difference,
count(*)
INTO
[pageviews-operatingsystems]
FROM
[stream_analytics_input] p
WHERE difference 
< 100
GROUPBY 
TumblingWindow(day,1), p.context.device.osVersion, p.context.data.eventTime

What am I doing wrong? I looked for this in the Stream Analytics from but could not find a working example of what I want. Thanks in advance.



推荐答案

好的,好吧,我回答了我自己的问题.最终使用了用户定义的udf javascript函数getCurrentDate(),这就是我最终得到的结果.我发现奇怪的是,您必须为javascript函数提供至少一个参数.如果你写 没有输入参数的类似东西

Ok, well guess I answered my own question. Ended up using a user defined udf javascript function getCurrentDate() so this is what I ended up with. What I find strange is that you have to supply at least one parameter to the javascript function. If you write something like this without input parameter

function getCurrentDate()
{ 返回新的Date();

function getCurrentDate()
{return new Date();}

这是完全有效的JavaScript!流分析不接受该功能.

which is perfectly valid javascript! The function is not accepted by stream analytics.

p .上下文. device . osVersion
p.context.device.osVersion,


这篇关于如何在查询中指定日期范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆