我正在寻求有关排名问题的帮助。我想要实现的目标是:按照customer_id和hit_datetime划分的等级参考标记点击,以便客户点击的最后一个项目按1排序。
例如,在下面的示例数据中,customer_id 836283461点击了五个不同的ref标记。但是,我希望当天该客户点击的最后一个参考标记排名第一。
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 48
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 50; // delay for half a second
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
for(int i=0;i<NUMPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(200,200,200)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
这是我的查询(为格式化道歉):
Rank | Hit Day | Time Stamp | Cust Id | Ref Marker
----------------------------------------------------------------------------------
1 | 13-DEC-15 | 23:06:24 | 836283461 | a_mt_contactus_ts1_d12_d29
1 | 13-DEC-15 | 23:06:33 | 836283461 | a_mt_contactus_ts1_d13_d23_d34
1 | 13-DEC-15 | 23:07:42 | 836283461 | a_mt_contactus_ts1_d17
1 | 13-DEC-15 | 23:07:49 | 836283461 | a_mt_contactus_ts1_d12_d29
1 | 13-DEC-15 | 23:07:54 | 836283461 | a_mt_contactus_ts1_d13_d23_d35
我相信我必须在我的时间戳分区中使用某种最大值函数,但却无法确切地知道如何去做。
----修改查询----
我将时间戳转换为秒,并按照上图所示组织结果。
SELECT
row_number () over(
partition by wma.customer_id, (to_char( wma.hit_datetime, 'HH24:MI:SS' ))
ORDER BY to_char( wma.hit_datetime, 'HH24:MI:SS' ) DESC
)
Hit_Rank,
wma.hit_day,
to_char( wma.hit_datetime, 'HH24:MI:SS' ),
wma.customer_id,
wma.ref_marker
FROM source_table wma
答案 0 :(得分:1)
SELECT ROW_NUMBER ()
OVER (PARTITION BY wma.customer_id, TRUNC (wma.hit_datetime)
ORDER BY wma.hit_datetime DESC)
Hit_Rank,
wma.hit_day,
TO_CHAR (wma.hit_datetime, 'HH24:MI:SS'),
wma.customer_id,
wma.ref_marker
FROM source_table wma