编写一个SQL查询,报告去年销量不足10册的书籍,但不包括从今天起不到一个月的书籍。假设今天是2019-06-23.
按任何顺序返回结果表。
查询结果格式如下所示。
我的代码:
with orders as
(
select
book_Id
,sum(quantity) as quantity
from
Orders
where dispatch_date > '2018-06-23'
Group by 1
)
select b.book_id
,b.name
from books b left join orders o using (book_id)
where quantity < 10
and available_from < '2019-05-23'
Output: {"headers": ["book_id", "name"], "values": [[1, "Kalila And Demna"]]}我的左键不是抓取书表中的所有书,而是拿走两张桌子上的书。挠我的头。
发布于 2022-05-09 01:47:24
如果您对订单数据感兴趣,那么您的主表应该是orders,那么就加入books表吧。
https://stackoverflow.com/questions/72166220
复制相似问题