zoukankan      html  css  js  c++  java
  • 子查询

    select b.id,b.dwmc,f.id,f.ORG_NAME,f.FILE_TYPE from tb_casq b LEFT JOIN tb_bid_file f on f.OWN_CODE= b.id where b.id='25a4d7fe020f628e93953881d56f03bf'

    申请表的id作为文件表的own_code  把两个表合并在一起

    把查出的四个不同类型的文件写在一条记录上

    SELECT b.id,b.dwmc,
    (SELECT f.id FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22001' ) f1id,
    (SELECT f.ORG_NAME FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22001' ) f1name,
    (SELECT f.id FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22002' ) f2id,
    (SELECT f.ORG_NAME FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22002' ) f2name,
    (SELECT f.id FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22003' ) f3id,
    (SELECT f.ORG_NAME FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22003' ) f3name,
    (SELECT f.id FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22004' ) f4id,
    (SELECT f.ORG_NAME FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22004' ) f4name
    FROM tb_casq b  WHERE b.id='25a4d7fe020f628e93953881d56f03bf'

    //查询多个

    SELECT b.id,b.dwmc,
    (SELECT f.id FROM tb_bid_file f WHERE f.OWN_

    CODE=b.id AND f.FILE_TYPE='22001' ) f1id,
    (SELECT f.ORG_NAME FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22001' ) f1name,
    (SELECT f.id FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22002' ) f2id,
    (SELECT f.ORG_NAME FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22002' ) f2name,
    (SELECT f.id FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22003' ) f3id,
    (SELECT f.ORG_NAME FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22003' ) f3name,
    (SELECT f.id FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22004' ) f4id,
    (SELECT f.ORG_NAME FROM tb_bid_file f WHERE f.OWN_CODE=b.id AND f.FILE_TYPE='22004' ) f4name
    FROM tb_casq b
    left join tb_bid_file f on b.id = f.OWN_CODE

     

    还有一个例子

    select a.*,b.is_win from 
    (SELECT b.id,b.projectname,b.qualifications,b.partya,b.winbidders,b.promanager,b.wintime,b.winmoney,b.protime,
    b.supervision_cotract,b.winbidnotice,b.customer,b.logother,b.infodate,b.infopeo,b.boolend,b.isin,b.kbtime,b.platform,b.original,b.Authorizer,
    (SELECT GROUP_CONCAT(companys) FROM TB_OA_ENTRY WHERE WINBIDID=B.ID ) tbdw,
    (SELECT SUM(QUALIFICATIONS_FEES) FROM TB_OA_ENTRY WHERE WINBIDID=B.ID ) tolzzfee,
    (SELECT SUM(WINBIDFEE) FROM TB_OA_ENTRY WHERE WINBIDID=B.ID ) tolwbfee, 
    (SELECT SUM(BOOKFEES) FROM TB_OA_ENTRY WHERE WINBIDID=B.ID ) tolbsfee, 
    (SELECT SUM(AUDITFEE) FROM TB_OA_ENTRY WHERE WINBIDID=B.ID ) tolsjfee,
    (SELECT SUM(PEOFEE) FROM TB_OA_ENTRY WHERE WINBIDID=B.ID ) tolryfee, 
    (SELECT ID FROM TB_BID_FILE WHERE OWN_CODE=B.ID AND FILE_TYPE ='0400001') tzsId,
    (SELECT ID FROM TB_BID_FILE WHERE OWN_CODE=B.ID AND FILE_TYPE ='0400002') htId 
    FROM TB_WINBID B WHERE 1=1 
    and boolend = '0100100' 
    AND BOOLEND <> '0100102' ORDER BY INFODATE DESC) a
    left join TB_OA_ENTRY b on b.winbidid = a.id where b.is_win = '0100100' 

  • 相关阅读:
    PTA L2-023 图着色问题-前向星建图 团体程序设计天梯赛-练习集
    PTA L2-004 这是二叉搜索树吗?-判断是否是对一棵二叉搜索树或其镜像进行前序遍历的结果 团体程序设计天梯赛-练习集
    PTA L2-006 树的遍历-二叉树的后序遍历+中序遍历,输出层序遍历 团体程序设计天梯赛-练习集
    HDU1166敌兵布阵(线段树单点更新)
    洛谷P1019——单词接龙(DFS暴力搜索)
    洛谷P1309——迷宫(傻瓜DFS)
    CodeForce-791B Bear and Friendship Condition(并查集)
    傻子都能懂的并查集题解——HDU1232畅通工程
    洛谷P1309——瑞士轮(归并排序)
    洛谷P1583——魔法照片(结构体排序)
  • 原文地址:https://www.cnblogs.com/Esther-yan/p/13413859.html
Copyright © 2011-2022 走看看