我有TContractForm
表idcontract(primary key),idcntrtype(foreign key),date_begin,date_end,cost
。此外,我已經得到了3種類型的合同:遇到問題
TRentWhouseContract
與領域idcontract,idclient,idpdtwhs
TRentShoppointContract
與領域idcontract,idclient,idshoppoint,idshoptype
TRentEquipContract
與領域idcontract,idclient,ideq,amount
idcntrtype
- 合同的類型。 TContractType
- idcntrtype(primary key),idcntrclass(foreign key),name
。 TContractClass
- idcntrclass,name
。
我想創建一個視圖與列 idcontract,idclient,contract_type(name of type),contract_class(name of class),date_begin,date_end,cost
。 (我知道我在TRentWhouseContract表中有幾個合同(其他表沒有行)(它沒有idclient,因爲我不知道如何從不同的表中獲得相同的idclient,如果有的話)表是空的)
select TCF.idcontract,
--idclient
TCF.date_begin,
TCF.date_end,
TCT.name as [type],
TCC.name as class,
TCF.cost
from TContractForm as TCF,
TRentEquipContract as TREC,
TRentShopPointContract as TRSPC,
TRentWhouseContract as TRWC,
TContractType as TCT,
TContractClass as TCC
where TCF.idcontract = TREC.idcontract or TCF.idcontract = TRSPC.idcontract
or TCF.idcontract = TRWC.idcontract and TCT.idcntrtype = TCF.idcntrtype
and TCT.idcntrclass = TCC.idcntrclass
我應該用戶'coalesce'? – lapots
是的。選擇TCF.idcontract,合併(TREC.idclient,...)作爲idclient,... – Joe