同时加入三张桌子?

时间:2015-12-28 18:18:02

标签: sql sql-server

我有一个包含多种交易类型的表。目前我只是提取调整和付款,但我需要将类型的ID与其描述相匹配。例如,我的交易表包含paytype_idadjustment_id,每个表的范围为1-100。我还有另外两个表dbo.paytypedbo.adjustments,它们具有不同的paytype_idadjustment_id以及描述哪种类型的pay_descadj_desc字段他们是。我遇到的问题是,任何给定的交易只会有paytype_idadjustment_id,但不能同时包含paytype_idadjustment_id。因此,如果我尝试加入一个表,那么另一个我丢失了辅助ID的NULL值

此查询将提取payment_id描述,但会因SELECT t.tran_num, t.resp_party_id, t.Total, t.paytype_id, t.adjustment_id, t.clinic, t.date_entered, p.pay_desc FROM adjpay_vw t CROSS JOIN paytype p WHERE (t.paytype_id = p.paytype_id AND t.clinic = p.clinic) 为空而删除adj_desc的所有交易。

dbo.adjustments

所以我想知道如何从pay_descdbo.paytype begin Retriable.retriable on: { Foo::Bar => /More specific timeout error message/ }, tries: 3 do # will retry if an error of type Foo::Bar is raised # and its message matches /More specific timeout error message/ # code here... end rescue => e # rescue for everything else puts e.message # same as e.to_s end 同时提取<!-- Upload multiple images with the extensions of png,jpg, jpeg & gif --> <div flow-init="{target: '/upload', singleFile: false}" flow-file-added="!!{png:1,gif:1,jpg:1,jpeg:1}[$file.getExtension()]" flow-files-submitted="$flow.upload()"> <div class="jumbotron"> <div class="container"> <div><span class="btn btn-default btn-selectimage" flow-btn flow-attrs="{accept:'image/*'}" onchange="previewFile()">Select image</span></div> <br><p>Only PNG,GIF,JPG files allowed.</p> </div> </div> <div> <div class="thumbnail" ng-hide="$flow.files.length"> <img src="images/no-images-placeholder.jpg" /> </div> <div class="thumbnail col-md-3" ng-show="$flow.files.length" ng-repeat="image in $flow.files"> <img id="image-handle" class="preview-blob" flow-img="image" /><br> <img class="preview" ng-src="{{imageStrings[$index]}}"/> <div class="image_option_controls"> <span class="btn glyphicon glyphicon-trash" ng-show="$flow.files.length" ng-click="image.cancel()"></span> <span class="btn glyphicon glyphicon-heart pull-right" ng-click="image.like()"></span> </div> </div> </div> </div>

1 个答案:

答案 0 :(得分:2)

通过在WHERE中使用连接条件,它会强制它的行为类似于INNER JOIN。而不是使用WHERE,将其添加到JOIN条件并转到LEFT JOIN。

SELECT t.tran_num, t.resp_party_id, t.Total, t.paytype_id, t.adjustment_id, t.clinic, t.date_entered, p.pay_desc, adj.adj_desc, ISNULL(p.pay_desc,adj.adj_desc) [Description]
FROM adjpay_vw t
LEFT JOIN paytype p ON t.paytype_id=p.paytype_id AND t.clinic=p.clinic
LEFT JOIN dbo.adjustments adj ON adj.adjustment_id = t.adjustment_id

此外,由于我不确定您的视图是否包含调整说明,因此我添加了一个联接,并添加了描述和显示说明的新列,无论是调整还是付款。