我有一张表,上面列出了每种产品在市场上上市的月份。例如产品1从3月到12月可用,产品2从1月到2月可用
end_month我使用dbFiddle来测试这个解决方案。这取决于每个月至少有一种产品可供销售。不过,也许在没有商品出售的情况下,一个月不退货更好?
可以使用@derviş-kayımbaşıoğlu方法生成月份,但不是product_id上的group,而是month。
with months as (
Select distinct start_month [month]
from Product
)
Select m.month
,count(*) [products]
from months m
left join Product p
on m.month >= p.start_month and m.month <= p.end_month
group by m.month
这样的东西需要帮助,但你可能有语法错误,因为我们不知道确切的DBMS和版本
select product_id, count(*) cnts
from table1
inner join (
select 1 month union
select 2 union
select 3 union
select 4 union
select 5 union
select 6 union
select 7 union
select 8 union
select 9 union
select 10 union
select 11 union
select 12 union
) t2
on t2.month between table1.start_month and table1.end_month
group by product_id
相关内容
- min(lag) over partition with conditions
- 如何在 Java 中显示"Invalid numbers with conditions"?
- MongoDB - Use $addToSet with conditions
- SQL COUNT with conditions
- SQL INSERT INTO WHERE NOT EXISTS with multiple conditions
- tSQL Partition by with conditions
- COUNT DISTINCT + WINDOW FUNCTION with conditions SQL Oracle
- Oracle SQL Pivot with Conditions将行转换为列
- Select Column Names With Conditions的SQL子查询
- MorphTo with conditions
- Oracle LISTAGG DISTINCT with multiple conditions
- MongoDB $lookup on Arrayof Ids with Conditions
- groupby with conditions并对python进行分类
- case_when with multiple conditions in dplyr R
- Pandasql with conditions
- Javascript For Loop with conditions
- scipy.optimize.curve_fit with conditions
- Google App Engine Python - Datastore: Conditions with db.Ref
- JSP: jstl core CONDITIONS with java.lang.Byte[]
- CakePHP: conditions with hasMany
最新更新
- 我有一个 roblox leaderstats 脚本,在 3 个不同的文件夹中有 2 个 IntValues,但它们无法正确保存。我不知道怎么了。我没有收到任何错误
- 为什么我得到Nodemailer不能/POST错误?
- 将数组转换为对象-具有特殊条件
- 如何在 JavaScript 中检查"is not defined" eval(var)?
- 错误NETSDK1152在WinUI3应用程序:发现多个发布输出文件具有相同的相对路径:Microsoft.Web.We
- 当我在Ubuntu16中使用字符串命令查找一些东西时,我没有得到任何输出
- Apache Spark: parse PT2H5M (duration ISO-8601) duration以分钟为单
- 如何在Parent还没有Id时添加Child
- 无法记录android应用程序的jmeter脚本
- 使用AsyncRabbitTemplate::sendAndReceive - RabbitMQ时的应答超时
- 是自定义文件扩展名吗?
- 选择远程docker容器(没有kubernetes)后, JVM列表为空
- c# TwinCAT数据类型的等效枚举
- 传递地址时,函数与函数模板的语法限制
- 如何将flutter riverpod ref.read()函数传递给另一个小部件
- Pug/Node.js中的循环优化
- Postgresql函数在删除t_providers的行之前作为触发器
- 在Python中替换字符串中类似模式的正则表达式
- Azure DevOps YAML:带有模板变量的If-else条件不起作用
- 我有麻烦管理我的循环while loo[,反之亦然
- 我怎么能使最后一行从图在PHP?
- 无法使用引导折叠折叠
- 当cell1的值大于cell2的值时显示模态对话框
- Vue模板使用JavaScript内置函数
- 使用python中除"in"以外的其他运算符"match"函数
- Powershell Where-Object returning null
- 在React中通过ClassName Prop扩展样式
- 如何缩小Firestore字段值
- 导入谷歌地图模块时反应错误
- 按顺序切换Class
热门标签:
javascript python java c# php android html jquery c++ css ios sql mysql arrays asp.net json python-3.x ruby-on-rails .net sql-server django objective-c excel regex ruby linux ajax iphone xml vba spring asp.net-mvc database wordpress string postgresql wpf windows xcode bash git oracle list vb.net multithreading eclipse algorithm macos powershell visual-studio image forms numpy scala function api selenium