mysql - 计算某些行 MySQL 的平均值
问题描述
我有 4 张桌子,如下图所示。我想打印CustomerName
谁在 2020 年第四季度支付的费用低于 2020 年第四季度的平均支付成本。
我试过使用这段代码,但它不起作用。有人可以帮我解决它!
select c.CustomerName, p.PaymentDate
from Payment p, Invoice i, BookingReq b, Customer c
where p.InvoiceID = i.InvoiceNum
and i.RequestID = b.RequestID
and b.CustomerID = c.CustomerID
and p.PaymentDate between '2020-10-01' and '2020-12-31'
and p.PaymentAmount < avg(if(p.PaymentDate between '2020-10-01' and '2020-12-31',
p.PaymentAmount,
NULL));
;
解决方案
推荐阅读
- c++ - Winapi - 删除编辑窗口边框c ++
- php - 路线 [student.contact] 未定义
- reactjs - Redux-Persist 没有在页面重新加载时保持我的状态
- python - Python:如何使用自定义比较器一次性对项目进行排序并删除重复项?
- android - ExoPlayer 未从 .srt 文件加载字幕
- python - MemberConverter 可以将服务器中的@提及作为 id 读取吗?
- amazon-web-services - Amazon S3、Amazon Athena 和 Amazon Athena 与分区的比较
- ubuntu - 如何恢复 nginx.conf
- reactjs - 更改道具时不会触发重新渲染
- apache-kafka - 当代理列表中的第一个代理关闭时创建生产者