zoukankan      html  css  js  c++  java
  • A表有字段a,B表有字段b,字段a中包含字段b,如何关联查询

    比如 AA表如
    xh  shengccj
    1   河南羚锐生物药业                                  
    2   四川蜀中制药有限公司                              
    3   海口奇力制药

    BB表 
    xh  shengccj
    1   河南羚锐生物
    1   河南中杰药业                                     
    2   四川蜀中制药
    2   海口奇力制药
    3   河南中杰药业 
    我想查询 的条件为 A表xh=b表xh   a表中shengccj 必须在b表中shengccj的
    结果为
    xh shengccj
    1   河南羚锐生物药业                                  
    2   四川蜀中制药有限公司   

    CREATE TABLE AA 
    (
        xh INT,
        shengccj VARCHAR(100)
    )
     
     
    INSERT INTO AA
    SELECT 1, '河南羚锐生物药业'
    UNION ALL 
    SELECT 2, '四川蜀中制药有限公司'
    UNION ALL 
    SELECT 3, '海口奇力制药'
     
    CREATE TABLE BB 
    (
        xh INT,
        shengccj VARCHAR(100)
    )
    INSERT INTO BB
    SELECT 1, '河南羚锐生物'
    UNION ALL 
    SELECT 1, '河南中杰药业'
    UNION ALL 
    SELECT 2, '四川蜀中制药'
    UNION ALL 
    SELECT 2, '海口奇力制药'
    UNION ALL 
    SELECT 3, '河南中杰药业'
    GO
    --开始查询
    --1
    select a.xh,a.shengccj from AA a left join BB b  on  a.xh=b.xh  where   b.shengccj like substring(a.shengccj,1,6)
    --2
    select a.xh,a.shengccj from  AA a ,BB b where a.xh=b.xh and b.shengccj like left(a.shengccj,6)
    --3
    select a.xh,a.shengccj from AA a,BB b where a.xh=b.xh and a.shengccj like '%'+b.shengccj+'%' --这个也可以出结果啊
    /*
    -----------------------------------------------------------------------
    xh    shengccj
    1     河南羚锐生物药业   
    2     四川蜀中制药有限公司
     
     
     
    (2 行受影响)
    ------------------------------------------------------------------------
    */
  • 相关阅读:
    运算符重载
    vmware 下 ubuntu 不能全屏显示 的解决方法
    最优化
    常见算法(logistic回归,随机森林,GBDT和xgboost)
    转:CRF++词性标注
    条件随机场(CRF)理论及应用
    转:RNN(Recurrent Neural Networks)
    RNN(Recurrent Neural Networks)公式推导和实现
    ML、DL相关资源
    机器学习(周志华西瓜书) 参考答案 总目录
  • 原文地址:https://www.cnblogs.com/albert-/p/14690693.html
Copyright © 2011-2022 走看看