如何编写SQL查询来通过排除克隆交付取消来获取已完成和取消交付的数量?
id | 送达 | parentid | 状态 |
---|---|---|---|
1 | parentdelivery1 | 0 | 取消 |
2 | 词 | 1 | 取消 |
3 | 1b | 1 | 完成 |
个 | clonedelivery1c | 1 | 取消 |
5 | parentDelivery2 | 0 | 取消 |
4 | Clonedelivery2A | 6 | typertype |
1a | 克隆 | 5 | |
| | 词 | |
克隆 | | | |
| | | |
这个 示例):
已完成交付的 | 已完成交货数量的 |
---|---|
数量2 | 2 |
所有父送货都有0,作为父级和克隆送货 在这里,如果完成了父母和克隆的1次交付,则应将其算作完成,并且应取消所有克隆的取消。
*父送货员可以有0个克隆
*克隆交付不会有自己的克隆
*如果取消父母的送达,但其克隆的任何1个都已完成,则应将其视为1件完成,并取消0(其他取消的取消,不应在取消的交货中计数
)应计算为1个取消。如何为此编写SQL查询?
我正在使用MySQL Workbench社区版本8.0.29
Id | deliverytype | parentId | status |
---|---|---|---|
1 | parentDelivery1 | 0 | cancelled |
2 | cloneDelivery1a | 1 | cancelled |
3 | cloneDelivery1b | 1 | completed |
4 | cloneDelivery1c | 1 | cancelled |
5 | parentDelivery2 | 0 | cancelled |
6 | cloneDelivery2a | 5 | cancelled |
7 | cloneDelivery2b | 5 | cancelled |
8 | cloneDelivery 2c | 5 | cancelled |
9 | parentDelivery3 | 0 | completed |
10 | parentDelivery4 | 0 | cancelled |
expected output(for this example):
number of completed deliveries | number of cancelled deliveries |
---|---|
2 | 2 |
All parent deliveries have 0 as parent id and clone deliveries have its parentId in parentId column
Here if even 1 delivery out of parent and clones is completed then it should count as completed and all clone cancellation should be eliminated.
*Parent deliveries can have 0 clones
*Clone deliveries will not have clone of its own
*If Parent delivery is cancelled but any 1 of its clone is completed then it should be considered as 1 completed and 0 cancelled(the other cancellations should not be counted under cancelled deliveries)
If all the delivery out of parent and clones is cancelled then it should be counted as 1 cancellation. How can I write an SQL query for this?
I am using MySQL workbench community version 8.0.29
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的释义逻辑...
这给了...
My paraphrased logic...
Which gives...