我在 hive 里工作。到目前为止,它真的很好,但我有一个问题,关于一个查询。
我有两个名为'marked'和'data'的表,希望通过一个查询从这两个表中提取数据。
首先,我想从表'marked'中提取mindate,并计算mindate(从'marked'获得)和当前日期之间的表'data'中的条目。
所以我想得到一个结果,其中包含userid,mindate,以及mindate和当前日期之间另一个表的这个userid的出现次数。我试着从几个小时后得到这个查询,但是我知道它们不起作用。有人能帮我吗?
谢谢!
更新:
对不起,我昨天有点赶时间。怪我忘了一些细节。
关于架构:
标记的表只有一些列。总共8个。以下是此表的架构:
"name": "Datetime",
"type": "long",
"logicalType": "timestamp-millis",
"name": "Hour",
"type": "string",
"name": "UserId64",
"type": "long"
"name": "MemberId",
"type": "int"
"name": "SegmentId",
"type": "int"
"name": "IsDailyUnique",
"type": "boolean"
"name": "IsMonthlyUnique",
"type": "boolean"
"name": "Value",
"type": "int"
另一个名为data的表的模式有点困难,因为这个表包含100多列。为了简单起见,我只列出了一些重要的专栏:
"name": "Datetime",
"type": "long",
"logicalType": "timestamp-millis",
"name": "Hour",
"type": "string",
"name": "UserId64",
"type": "long"
"type": "enum",
"name": "EventType",
"symbols": ["IMP", "CLICK", "PC_CONV", "PV_CONV"]
所以如果我像下面这样做一个查询,我会得到一个包含结果的列表
选择timestamp(datetime),hour,userid64,segmentid,isdailyunique,ismonthlyunique,date from marked where userid64=8012570064195370898 and segmentid=1878696 order by datetime desc;
结果表包含数据。现在我想使用最早的获取日期进行进一步的查询。
如果我们转到表数据并执行以下查询
选择timestamp(datetime)、auction64、hour、eventtype、mediacostdollarscpm、buyerspend、buyerbid、ecp、eap、isimp、isclick、userid64、sellerid、publisherid、siteid、sitedomain、advertiseirid、advertiserfrequency、advertiserrecent、campaigngroupid、campaignid、creativeid、creativefreq、creativerec、pixelid、dealid、dealtype、custommodelid,custommodellastmodified,leafname,datetime from data where userid64=8012570064195370898 and advertiserid=327758 order by datetime desc;
您将得到如下所示的结果
2016-08-09 19:33:45.0 5908114946988383281 17 PV_CONV
2016-08-07 19:17:13.0 5908114946988383281 17 IMP
2016-08-07 19:16:29.0 5454485145188351263 17 IMP
2016-08-07 18:52:40.0 1074433759230515153 16 IMP
2016-08-07 18:52:40.0 6991642005216308404 16 IMP
2016-08-07 18:52:13.0 5024645171257244072 16 IMP
2016-08-07 18:51:55.0 5371107932239703086 16 IMP
2016-08-07 18:51:55.0 7321752276741166764 16 IMP
2016-08-07 18:51:01.0 3459181835067844898 16 IMP
2016-08-07 18:50:42.0 6208818658549255015 16 IMP
2016-08-07 18:50:41.0 5373958128201701132 16 IMP
2016-08-07 14:34:07.0 8393280749656213703 12 IMP
这里的导入行是第二行。后面有一个标志叫“pv\u conv”。
我想要的是:
我想要一个查询,生成一个包含
用户ID
标记的表的最小日期
包含事件类型“imp”的表数据的最大日期
表数据的标记日期和最大日期之间的时间差
以及表数据的其他一些列。
有没有可能在不创建其他表的情况下得到这个结果?祝你一切顺利,谢谢彼得
1条答案
按热度按时间qvsjd97n1#
因为没有提供表模式,所以我假设下表模式可以回答您的问题。。
表-标记:
UserID int, mindate date
表-数据:UserID int, data_date date
将userid作为联接表的主列,下面是查询取决于
'Date'
表中的数据类型,需要更改where子句。。