2017-04-19 174 views
-2
select distinct 
    i.legacydatetime, 
    i.legacypatientreceivablespatientid, 
    bs.invoiceid, 
    billingserviceid, 
    case 
     when billingserviceid not in (select billingserviceid 
            from model.billingservices 
            where id not in (select billingserviceid 
                 from model.adjustments 
                 where billingserviceid is not null)) 
     then bs.unit * bs.unitcharge 
     else bs.unit * bs.unitcharge + total_amount 
    end as Open_Balance 

时,我有2个表model.billingservicesmodel.adjustments其中billingservices表的ID是adjustments表作为billingserviceid外键。Case语句的语法使用IN

我想隔离开来billingservices表中不存在的调整表等的,我需要应用一些条件,否则,如果ID存在于调整表的ID,然后在需要应用一些其他条件

+0

您错过了开始处的select关键字。什么是你得到的错误消息 – Jens

+1

如果你不打算发布整个查询至少发布错误消息,你得到 –

+0

看到我想要的是:我正在采取的情况下,如果假设有2个表,名为billingservices并进行调整,而billingserviceid是调整表中的外键好吗!所以现在如果在billingservice表中的billingserviceids不存在于调整中,那么对于那些billingserviceids应该有一些条件,现在建议 –

回答

2
billingserviceid not in (select * from model.billingservices.... 

在这里,您是通过使用*与model.billingservices表的多个列的比较billingserviceid。请提及您打算与billingserviceid进行比较的单列名称。 *会返回所有列值。

+0

是的,我纠正了,仍然没有得到所需的输出。 –

+0

发布您更正的查询。 – Kapil

+0

您不能在子选择中使用'select *'作为'IN'运算符,您*有*仅选择子选择中的单个列。这将导致一个错误(除非billingservices具有一列) –