本文介紹了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 幫助:異常報告 - 擴展的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!