代码之家  ›  专栏  ›  技术社区  ›  Venkat

基于2列减去2个表

  •  0
  • Venkat  · 技术社区  · 14 年前

    “帐单”中不存在 基于 两列。

    目前我提出了这个问题:

    SELECT ControlNum, CarrierName, PhoneNum, PatientName, SubscriberID, SubscriberName, 
    ChartNum, DoB, SubscriberEmp, VisitID, ServiceDate, ProviderName, CPTCode, BillingDate, 
    AgingDate, BalanceAmt, Age, AgeCategory FROM billing_temp LEFT JOIN billing 
    USING (ControlNum, CPTCode) WHERE billing.ControlNum=billing_temp.ControlNum AND 
    billing.CPTCode=billing_temp.CPTCode
    

    Column 'ControlNum' in fieldlist is ambiguous.
    

    有人面对过这种情况吗。

    注:

    很抱歉,我在自己的查询中发现了问题所在。。 感谢所有关心我问题并发送答案的人。。

    4 回复  |  直到 11 年前
        1
  •  2
  •   Tobiasopdenbrouw    14 年前

    如果字段存在于多个表中,则每次出现字段名(在查询中)都必须完全限定。对你来说也是 billing.ControlNum billing_temp.ControlNum

        2
  •  2
  •   Matt Gibson    14 年前

    如果您想选择“billing\u temp”中不存在的“billing\u temp”行,我可以尝试以下方法(

    SELECT
      ControlNum, CarrierName, PhoneNum, PatientName, SubscriberID, SubscriberName, 
      ChartNum, DoB, SubscriberEmp, VisitID, ServiceDate, ProviderName, CPTCode, BillingDate, 
      AgingDate, BalanceAmt, Age, AgeCategory 
    FROM
      billing_temp
    WHERE 
      NOT EXISTS (
        SELECT
          * 
        FROM 
          billing 
        WHERE 
          billing.ControlNum=billing_temp.ControlNum AND 
          billing.CPTCode=billing_temp.CPTCode
      )
    
        3
  •  2
  •   Venkat    14 年前

    以下是绝对查询:

    SELECT bt.ControlNum, bt.CarrierName, bt.PhoneNum, bt.PatientName, bt.SubscriberID, 
    bt.SubscriberName, bt.ChartNum, bt.DoB, bt.SubscriberEmp, bt.VisitID, bt.ServiceDate, 
    bt.ProviderName, bt.CPTCode, bt.BillingDate, bt.AgingDate, bt.BalanceAmt, bt.Age, 
    bt.AgeCategory FROM billing_temp bt LEFT JOIN billing ON 
    bt.ControlNum=billing.ControlNum AND bt.CPTCode=billing.CPTCode
    
        4
  •  0
  •   AndreyKo DaveE    14 年前

    尝试:

    SELECT billing_temp.ControlNum, CarrierName, PhoneNum, PatientName, SubscriberID, SubscriberName, 
    ChartNum, DoB, SubscriberEmp, VisitID, ServiceDate, ProviderName, CPTCode, BillingDate, 
    AgingDate, BalanceAmt, Age, AgeCategory FROM billing_temp LEFT JOIN billing 
    USING (ControlNum, CPTCode) WHERE billing.ControlNum IS NULL
    

    规则是: 如果要选择表A中出现但未出现在表B中的所有行,则应选择“A LEFT JOIN B”中在B中为空的所有行。