0

查询是获取每个表的日期,我已经检查了我的代码,但它仍然是错误的“每个派生表必须有自己的别名错误”


SELECT T.* 
    FROM (
     SELECT DISTINCT(DATE_FORMAT(p.deliverDate, '%M')) as PDate
     FROM piglet_po p 
     WHERE p.raiserID = '0025' AND p.rotationNo = '3' 

        AND p.deliverDate NOT IN 
        ( SELECT DISTINCT(DATE_FORMAT(f.issuedDate, '%M')) as FDate
           FROM feed_slip f             
           WHERE f.raiserID = '0025' AND f.issuedDate BETWEEN '2012-06-01' AND '2012-11-01'                

           AND f.issuedDate NOT IN 
           ( SELECT DISTINCT(DATE_FORMAT(v.issuedDate, '%M')) as VDate
              FROM vet_slip
              WHERE v.raiserID = '0025' AND v.issuedDate BETWEEN '2012-06-01' AND '2012-11-01'

            AND v.issuedDate NOT IN 
             ( SELECT DISTINCT(DATE_FORMAT(w.issuedDate, '%M')) as WDate
                FROM weight_slip w  
                WHERE w.raiserID = '0025' AND w.issuedDate BETWEEN '2012-06-01' AND '2012-11-01'                                     
              ) 
          ) 

      ) T
4

1 回答 1

1

您忘记了别名v

        SELECT DISTINCT(DATE_FORMAT(v.issuedDate, '%M')) as VDate
          FROM vet_slip
         WHERE v.raiserID = '0025' AND 
               v.issuedDate BETWEEN '2012-06-01' AND '2012-11-01'

还缺少一个右括号,AFAICT。如果您只是删除了最后一个,则别名T位于错误的位置。我假设这是被删除的“内括号”之一。

因此,更正后的查询是:

SELECT T.* 
  FROM (SELECT DISTINCT(DATE_FORMAT(p.deliverDate, '%M')) as PDate
          FROM piglet_po p 
         WHERE p.raiserID = '0025' AND p.rotationNo = '3'
           AND p.deliverDate NOT IN 
               (SELECT DISTINCT(DATE_FORMAT(f.issuedDate, '%M')) as FDate
                  FROM feed_slip f             
                 WHERE f.raiserID = '0025'
                   AND f.issuedDate BETWEEN '2012-06-01' AND '2012-11-01'
                   AND f.issuedDate NOT IN 
                       (SELECT DISTINCT(DATE_FORMAT(v.issuedDate, '%M')) as VDate
                          FROM vet_slip v
                         WHERE v.raiserID = '0025'
                           AND v.issuedDate BETWEEN '2012-06-01' AND '2012-11-01'
                           AND v.issuedDate NOT IN
                               (SELECT DISTINCT(DATE_FORMAT(w.issuedDate, '%M')) as WDate
                                  FROM weight_slip w
                                 WHERE w.raiserID = '0025'
                                   AND w.issuedDate BETWEEN '2012-06-01' AND '2012-11-01'
                               ) 
                       ) 
               )
       ) T
于 2012-07-16T01:55:24.387 回答