SELECT * FROM jcb_t_asset_combo_item AS jtaci **INNER join** (select pType,pId,(**CASE WHEN ISNULL(pTrustId)** THEN pFundId ELSE pTrustId END) AS choiceId FROM jcb_t_product) AS product ON product.pId = jtaci.itemRelatedProduct //连接一个查询出结果的表,该查询出来的结果表有三个字段。type,id,choiceId、 其中Choiceid是通过case When 语句进行判断的。得出来的choiceId 在和下面的新生成的表进行连接 INNER JOIN ( select product_name as pname ,product_id AS detailId ,product_period AS pqixian, product_rate AS pshouyi ,1 as type from jcb_tnonstandardproduct union select pFundName as pname ,pFundId AS detailId ,dataDate AS pqoxian ,tenThousandBenifitRate AS pshouyi,2 as type from jcb_t_standerproduct_fund ) AS detail **ON detail.detailId = product.choiceId** and detail.type=product.pType //此连接的表也是新生成的,通过union关键字,进行两个不同的类型的字段进行联合。同时与上一个表的choiceId进行对接 WHERE jtaci.itemRelatedAssetPack = 2
sql 链表查询语句
原文作者:SQL
原文地址: https://blog.csdn.net/mimi5821741/article/details/48195851
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: https://blog.csdn.net/mimi5821741/article/details/48195851
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。