sql - 金额少于 200 多长时间
问题描述
我需要确定少于 200 的金额有多长时间。
我的数据集看起来像
Id user time amount max_amount
25 3618 1 0 1
25 3618 1 17040 3
25 3618 1 30 2
27 4281 1 0 1
27 4281 1 14188 3
27 4281 1 17372 4
27 4281 1 190 2
等等
生成它的代码如下:
Select t2.id, t2.user, t1.time, sum(t1.amount_amt as float) / (t1.eur_amt as float) as amount,
rank () over (partition by t2.user order by amount) max_amount
From table1
Inner join table2 as t2
on t1.user=t2.user
Group by 1,2,3
我的预期输出是
Id user time spent
25 3618 1 2
27 4281 1 2
我怎么能得到这个结果?
解决方案
我想你只想要过滤和聚合:
select id, user, time, count(*)
from t
where amount < 200
group by id, user, time;
如果该表是由问题中的代码生成的,则可以在上述查询之前使用 CTE:
with t as (
<query>
)
推荐阅读
- javascript - 如何在材质 UI 表中创建子标题
- python - 为什么可变数据类型生成的哈希码不能成为python中的字典键?
- scheduled-tasks - 无法安排录音功能
- flutter - 升级到 Flutter 到 2.5.0 后,无法从 Android Studio 的 iOS 模拟器运行应用程序
- redis - 如何创建没有副本的redis集群
- python-3.x - 二维列表操作
- java - 我正在尝试创建许多与从文件中读取的行数相同的 Employee 对象
- c# - 如何从 C# WPF 中的嵌入字体将字体文件添加到 Stimulsoft 报告
- reactjs - 当我通过身份验证包装组件时,Nextjs 未呈现服务器端
- java - 无法从 url 加载 PDF