当前位置: 首页 > 知识库问答 >
问题:

当至少存在一条不符合条件的记录时,不会返回任何记录

燕意蕴
2023-03-14

首先,我知道这个查询有点混乱,但它可以正常工作,直到至少有一条ticket记录存在,并且cancelled设置为true,此时没有返回任何记录。如果有另一条记录的已取消设置为false或两者的组合,则它可以正常工作,即返回的记录的所有票证总数都设置为0或适当的值。

我已将查询更新为where。。。t、 cancelled=0或t.cancelled为NULL,并将票证表联接更改为left(也尝试了full outer),但它仍然存在上述问题。

为什么会发生这种情况,我能做些什么来防止它?

select Title, PerformanceStarts, sum(sold) as sold, sum(sold * value) as revenue, idperformance, DoorsOpening, onsale, active, showactive, venueid,
    (
        select sum(Quantity) from allocations
        where IdAllocation in (select allocationid from PerformancePriceBands where PerformanceID = idperformance) and OnGeneralSale = 1) as alloc, 
            (
                select count(totaltickets) from
                    ( 
                        select count(t.idticket) as totaltickets from tickets t
                        where t.PerformancePriceBandID IN
                            (
                                select idperformancepriceband from PerformancePriceBands
                                where performanceid = IdPerformance) and (t.Cancelled = 0 or t.Cancelled IS NULL)
                                group by t.BookingID
                            ) as q
                where totaltickets > 7
            ) as largegroups,
            (
                select count(totaltickets) from
                    ( 
                        select count(t.idticket) as totaltickets from tickets t
                        where t.PerformancePriceBandID IN
                            (
                                select idperformancepriceband from PerformancePriceBands
                                where performanceid = IdPerformance) and (t.Cancelled = 0 or t.Cancelled IS NULL)
                                group by t.BookingID
                            ) as q
                where totaltickets between 5 and 7
            ) as mediumgroups
    from
        (
            select p.idperformance, s.title, p.PerformanceStarts, count(t.idticket) as sold, ppb.Value, p.DoorsOpening, p.OnSale, p.Active, s.active as showactive, p.VenueID
            from shows s
            join performances p on p.ShowID = s.IdShow
            join PerformancePriceBands ppb on ppb.PerformanceID = p.IdPerformance
            left join tickets t on t.PerformancePriceBandID = ppb.IdPerformancePriceBand
            where p.IdPerformance = 23206 and (t.Cancelled = 0 or t.Cancelled is null)
            group by s.title, p.performancestarts, ppb.Value, p.idperformance, p.DoorsOpening, p.onsale, p.active, s.active, p.VenueID
        ) as q
group by title, PerformanceStarts, IdPerformance, DoorsOpening, onsale, Active, showactive, VenueID

共有1个答案

艾茂学
2023-03-14

尝试将取消的条件移动到联接条件。

left join tickets t on t.PerformancePriceBandID = ppb.IdPerformancePriceBand and t.Cancelled = 0

并将其从place子句中删除。

 类似资料:
  • 问题内容: 我有这样的一对一关系 父母 和孩子 } 我想创建返回具有孩子isNotNull的父母的条件,我尝试过像 但是没有用,请给我一个例子,能帮我吗?谢谢 问题答案: 首先,映射是错误的。在父类中,您是说该关联是由映射的,而在您说该关联是使用名为的连接列进行映射之后。下定决心 它是由属性映射的,应该删除。或者它是由JoinColumn映射的,您应该在子级中删除,并在Child实体中使用。 现在

  • 我有一个动觉流(20个片段),大约有1天的数据延迟,这是由基于KCL的动觉消费者消费的。消费者部署了20个ECS实例,因此每个实例都有一个从每个shard提取数据的线程。 根据文档,看起来一个getRecords调用最多可以获取10000条记录,或者最大负载大小为10 MB。然而,当我监视消费者日志时,并不是所有的碎片都达到了这个限制。使用单个getRecords调用获取的记录在消费者实例中非常不

  • 问题内容: 编辑:糟糕,我想如果发布删除代码会有所帮助。抱歉。 我正在使用Spring Data / JPA V 1.4.2.RELEASE和hibernate3.6.10.Final。 我遇到的情况是删除一个实体,删除似乎可以正常工作,但是当我刷新网页时,该实体会重新出现。因此,它不会产生错误,但不会删除记录。 该实体中包含子实体。我怀疑某种实体依赖问题会阻止实体真正被“删除”,但我不知道它可能

  • 对于Ex:有两个表: 表1-教师, 表2-学生 在教师表中,包含教师的详细信息 在学生表中,它包含学生的详细信息 如你所见,一个老师与多个学生联系在一起。我想选择那些所有学生都通过考试的老师(及格分数为40)。例如:Teacher_Id=2的老师与3个学生分别获得28、90、78分。这里是28分的学生考试不及格。所以,我们不会选择那个老师。我们不会选择那些即使有一个学生得分低于40分的老师。我们必

  • 我们正在使用Spring Kafka 2.2.2版本从Kafka中检索记录,使用@KafkaListener和Con电流tKafkaListenerContainerFactory。我们已经配置了max-pore-记录为5,但是它总是在列表中只给消费者1条记录,而不是5条记录。 虽然配置相同,但它在Spring Kafka 2.1中也能工作。4.释放。 这是我们的申请表。yml配置: 以下是我们的

  • 问题内容: 我有以下数据: 对于每组记录(按ParentID分组),我想查找所有没有包含“ A”作为数据值的记录的组。 由于第1组和第6组确实包含至少一个以“ A”作为数据值的记录,因此我不希望看到它们。我只想查看记录4和5(它们是组4的一部分),因为该组中没有记录带有“ A”。 任何帮助是极大的赞赏! 问题答案: 如果表很大,建议建立索引。