SQL 帮助:异常报告 - 扩展

SQL Help : Exception report - extended(SQL 帮助:异常报告 - 扩展)
本文介绍了SQL 帮助:异常报告 - 扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

扩展:SQL 帮助 - 异常报告

在我之前的帖子中,我请求肝:

In my previous post I requested hep for:

我有:

  • 一个公司表(CompanyID、CompanyName),
  • 日期表(Datekey int, date, isTradingHoliday 0/1),
  • 事实表(id、datekey、c​​ompanyID、StockClosePrice)

我需要帮助编写查询以查找事实表中没有数据的日期和公司.

I need help to write a query to find for which days and for which companies I don't have data in the fact table.

下面的 SQL 完成工作

SQL below does the job

select c.*, d.*
from companies c
cross join dates d 
where d.isTradingHoliday = 0
  and not exists (select 1 from facts f 
                  where f.datekey = d.datekey and f.companyID = c.companyID) 

我注意到有些公司的StockClosePrice 是 0.00 - 我想将它们包含在异常报告中.

I have noticed for some companies, for some days, StockClosePrice is 0.00 - I want to include those in the exception report.

感谢任何帮助

推荐答案

我想你只是想在子查询中多一个条件:

I think you just want one more condition in the subquery:

where d.isTradingHoliday = 0 and
      not exists (select 1
                  from facts f
                  where f.datekey = d.datekey and
                        f.companyID = c.companyID and
                        f.StockClosePrice <> 0.00
                 ) 

这篇关于SQL 帮助:异常报告 - 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)