database - 在查询中为子选择添加条件
问题描述
我有这个查询
SELECT DISTINCT
u.email,
(
SELECT
count(DISTINCT o.id)
FROM
orders o
INNER JOIN cart_dates cd ON cd.order_id = o.id
WHERE
u.id = o.user_id
) as count
FROM
users u
count
仅当例如 < 20 时,我如何才能获取行?
解决方案
你可以使用group by
andhaving
子句。
select u.email
from users u
inner join orders o on o.user_Id = u.id
inner join card_dates cd on cd.order_id = o.id
group by u.email
having count(distinct o.id) < 20
推荐阅读
- python - 如何为数据框中的多个项目创建颜色字典?
- java - 使用 System.out::print 打印 String[] 时如何附加分隔符字符串?
- html - 使用 jQuery 或纯 CSS 进行无限背景滚动
- git - 一些合并请求后,我仅来自一个文件的代码消失了,为什么?
- bash - 将变量的值传递给命令,就好像它存储在文件中一样
- django - 让 Django/DRF 接受不带斜杠的 url
- flutter - 如何从 Firestore 获取当前的 UserId?
- django - Django:即使使用缓存中的数据,模板加载也很慢
- syntax-highlighting - Quizlet 中用于语法高亮的 Google 扩展
- javascript - 如何以特定用户代理的身份发送请求