0

我有这个问题。我使用了这个查询:

"SELECT  formas.*,
        SMS_SERVISI.IDTICKET,
        SMS_SERVISI.MBYLLUR,
        SMS_SERVISI.time_added,
        servis_furnitor.id_servis,
        servis_furnitor.furnitori,
        servis_furnitor.kohezgjatja,
               referenca.id_referenca,
        referenca.shenime

FROM formas
LEFT JOIN servis_furnitor
        ON formas.furnitori = servis_furnitor.id_servis
LEFT JOIN SMS_SERVISI
        ON formas.ID = SMS_SERVISI.IDTICKET
        AND formas.sektori_pergjegjes ='A'
        LEFT JOIN referenca
        ON formas.ID = referenca.id_referenca  "

我的问题是我没有得到条件的一部分AND formas.sektori_pergjegjes ='A' 没有执行。也许我做了错位或其他事情,但我无法让它工作。

请看看这个。谢谢

4

3 回答 3

1

该条件AND formas.sektori_pergjegjes ='A'仅对连接结果执行,因为它是连接条件的一部分。如果您希望所有数据都符合您的过滤器,则需要将其移动到 where 子句中。

SELECT  formas.*,
        SMS_SERVISI.IDTICKET,
        SMS_SERVISI.MBYLLUR,
        SMS_SERVISI.time_added,
        servis_furnitor.id_servis,
        servis_furnitor.furnitori,
        servis_furnitor.kohezgjatja,
        referenca.id_referenca,
        referenca.shenime    
FROM formas
LEFT JOIN servis_furnitor
        ON formas.furnitori = servis_furnitor.id_servis
LEFT JOIN SMS_SERVISI
        ON formas.ID = SMS_SERVISI.IDTICKET
LEFT JOIN referenca
        ON formas.ID = referenca.id_referenca
WHERE formas.sektori_pergjegjes ='A'
于 2013-03-15T09:36:39.910 回答
0

将和条件放在哪里,看看它是否解决了

"SELECT  formas.*,
        SMS_SERVISI.IDTICKET,
        SMS_SERVISI.MBYLLUR,
        SMS_SERVISI.time_added,
        servis_furnitor.id_servis,
        servis_furnitor.furnitori,
        servis_furnitor.kohezgjatja,
               referenca.id_referenca,
        referenca.shenime

FROM formas
LEFT JOIN servis_furnitor
        ON formas.furnitori = servis_furnitor.id_servis
LEFT JOIN SMS_SERVISI
        ON formas.ID = SMS_SERVISI.IDTICKET

        LEFT JOIN referenca
        ON formas.ID = referenca.id_referenca 
 WHERE formas.sektori_pergjegjes ='A' "
于 2013-03-15T09:35:24.187 回答
0

尝试:

"SELECT  formas.*,
    SMS_SERVISI.IDTICKET,
    SMS_SERVISI.MBYLLUR,
    SMS_SERVISI.time_added,
    servis_furnitor.id_servis,
    servis_furnitor.furnitori,
    servis_furnitor.kohezgjatja,
           referenca.id_referenca,
    referenca.shenime

FROM formas
LEFT JOIN servis_furnitor
    ON formas.furnitori = servis_furnitor.id_servis
LEFT JOIN SMS_SERVISI
    ON formas.ID = SMS_SERVISI.IDTICKET
LEFT JOIN referenca
    ON formas.ID = referenca.id_referenca  
WHERE formas.sektori_pergjegjes ='A'"
于 2013-03-15T09:36:01.813 回答