问题描述
row_num() partition by month order by day_date desc
我的结果是这样的,不限于-仅举个例子
Month Day User Active row_num
Jan-2021 2021-01-28 A yes 1
Jan-2021 2021-01-27 A yes 2
Jan-2021 2021-01-28 A yes 3
Feb-2021 2021-02-25 A no 1
Feb-2021 2021-02-15 A yes 2
Feb-2021 2021-02-01 A no 3
Jan-2021 2021-01-28 B yes 1
Jan-2021 2021-01-28 B yes 2
Jan-2021 2021-01-28 B yes 3
Feb-2021 2021-02-28 B no 1
Feb-2021 2021-02-08 B yes 2
我想添加的附加内容是,如果用户在月底处于活动状态,我想将月份标记为活动状态。逻辑是,如果 row_num = 1 且 active = yes,则标记整月,反之亦然 row_num = 1 且 active = 无标记 month_active = no。
我目前被困在如何将值应用于月份的分区,但在每日级别进行评估。提前欣赏。
Month Day User Active row_num month_active
Jan-2021 2021-01-28 A yes 1 yes
Jan-2021 2021-01-27 A yes 2 yes
Jan-2021 2021-01-28 A yes 3 yes
Feb-2021 2021-02-25 A no 1 no
Feb-2021 2021-02-15 A yes 2 no
Feb-2021 2021-02-01 A no 3 no
Jan-2021 2021-01-28 B yes 1 yes
Jan-2021 2021-01-28 B yes 2 yes
Jan-2021 2021-01-28 B yes 3 yes
Feb-2021 2021-02-28 B no 1 no
Feb-2021 2021-02-08 B yes 2 no
解决方法
一种方法是使用import cv2
import numpy as np
import pyautogui
SCREEN_SIZE = (1920,1080)
#define the codec
fourcc = cv2.VideoWriter_fourcc(*"XVID")
#create the video write object
out = cv2.VideoWriter("output.avi",fourcc,20.0,(SCREEN_SIZE))
while True:
#make a screenshot
img = pyautogui.screenshot(region=(680,785,560,20))
#convert these pixels to a proper numpy array to work with OpenCV
frame = np.array(img)
#convert colors from BGR to RGB
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
black = [0,0]
for x in range(img.width):
for y in range(img.height):
if img.getpixel((x,y)) == black:
print(x,y)
pyautogui.click(x,y)
#write the frame
out.write(frame)
#show the frame
cv2.imshow("screenshot",frame)
# if the user clicks q,it exits
if cv2.waitKey(1) == ord("q"):
break
# make sure everything is closed when exited
cv2.destroyAllWindows()
out.release()
:
first_value()
或者,如果您将查询用作子查询,则可以使用:
select t.*,first_value(active) over (partition by month order by day desc) as month_active
from t;