TableDates
================
- mDate
tblLocations
================
- location_id
- location
tblSignature_labels
===================
- signature_label_id
- signature_label
- isrequired bit
tblsignatures
====================
- location_id
- signature_label_id
- signature_date
我需要显示tblsignatures
表中tblsignatures.signature_date = tblDates.mdate
以及tblSignature_labels.isrequired=1
和tblLocations.location_id=tblSignatures.location_id
因此,如果需要其中一个signature_labels并且location_id
和该位置的日期不在签名表中,请列出不在签名表中的日期,位置和签名标签...清除为泥吧?
任何人都可以帮助兄弟在这里:)
答案 0 :(得分:0)
使用cross join
生成前三个表的所有组合。然后是一些更多逻辑(例如left join
)来排除已填充的逻辑:
select d.mdate, l.location_id, sl.signature_label
from tableDates d cross join
tblLocations l cross join
tblSignature_labels sl left join
tblsignatures s
on s.location_id = l.location_id and
s.signature_label_id = sl.signature_label_id and
s.signature_date = d.mDate
where s.location_id is null;