MySQL未知列

时间:2010-08-03 23:42:42

标签: sql mysql mysql-error-1054

为什么我收到此错误:

1054 - '字段列表'

中的未知列't.type'

我的表中有一个名为type的列。我使用别名来获得表'测试'。

SELECT y.*,
           (SELECT COUNT(*)
              FROM (SELECT *, 
                           CASE t.type
                             WHEN 'Advanced' THEN t.type
                             ELSE 'Non-Advanced'
                           END AS group_type
                      FROM tester) x
             WHERE x.group_type = y.group_type
               AND (x.grade1 + x.grade2) >= (y.grade1 + y.grade2)) AS rank
      FROM (SELECT t.name,
                   t.grade1,
                   t.grade2,
                   t.type,
                   CASE t.type
                     WHEN 'Advanced' THEN t.type
                     ELSE 'Non-Advanced'
                   END AS group_type
              FROM tester t) y

OMGPonies,有什么想法吗?

谢谢。

-Laxmidi

2 个答案:

答案 0 :(得分:3)

我的额头 - 我的错,对不起。

使用此:

SELECT y.*,
       (SELECT COUNT(*)
          FROM (SELECT *, 
                       CASE type
                         WHEN 'Advanced' THEN type
                         ELSE 'Non-Advanced'
                       END AS group_type
                  FROM tester) x
         WHERE x.group_type = y.group_type
           AND (x.grade1 + x.grade2) >= (y.grade1 + y.grade2)) AS rank
  FROM (SELECT t.name,
               t.grade1,
               t.grade2,
               t.type,
               CASE t.type
                 WHEN 'Advanced' THEN t.type
                 ELSE 'Non-Advanced'
               END AS group_type
          FROM tester t) y

答案 1 :(得分:1)

子查询出错 - 此处未定义别名t

          (SELECT *, 
          CASE t.type
            WHEN 'Advanced' THEN t.type
            ELSE 'Non-Advanced'
          END AS group_type
          FROM tester)x ....