sql - SQL duplicated visitors per product
问题描述
I have a Main table and visitors and I link them up by Date and Hour( I have only Date, hour and Visitors in Visitors table)
This is my table
DATE HOUR ORDER_ID ITEM VISITORS
2018-09-25 14 123456 Box 140
2018-09-25 14 345677 Paper 140
2018-09-25 14 234678 Bear 140
BUT I need somehow to make it like this, to remove duplicated visitors, is it possible at all?
DATE HOUR ORDER_ID ITEM VISITORS
2018-09-25 14 123456 Box 140
2018-09-25 14 345677 Paper
2018-09-25 14 234678 Bear
I'm looking for logic to understand how to do it. As I need Visitors in the same table
解决方案
你似乎想要:
select date, hour, order_id, item,
(case when row_number() over (partition by date, hour order by order_id) = 1
then visitors
end) as visitors
from t;
这将visitors
只包括给定日期和时间的一行。
推荐阅读
- command-line-interface - Julia `--project` 命令行选项中的`@.` 是什么?
- python - Python - 如何解决 Web 服务器连接限制
- angular - 我可以将对象及其方法存储在@ngrx 中吗
- jwplayer - 如何阻止JW播放器控制栏在播放过程中淡出?(JW 8)
- winforms - c# - 如何使用 7z 函数将每个 zip 文件从源文件夹放入目标文件夹
- ruby-on-rails - Rspec 请求规范检查响应正文
- python - 通过更改批量大小和输入图像大小来提高准确性
- javascript - 如何从 Angular 中的 api 响应中获取数据
- javascript - 如何在 Framework7 上居中登录卡?
- r - 在 R 中使用 dplyr 编写一种 for 循环