MySql Where和And语句在Join中引发错误

时间:2016-10-04 06:38:36

标签: mysql

我正在尝试执行以下声明

SELECT ORDER_MONTH,
SUM(PRICE) as Price    
FROM  (SELECT EXTRACT(YEAR FROM ORDERDATE) AS ORDER_YEAR,    
MONTHNAME(ORDERDATE) AS ORDER_MONTH,        
ORDERDATE, PRICE  FROM ORDER_ABSTRACT)A
WHERE ORDER_YEAR=2016 AND SKU=4567 
GROUP BY MONTH(ORDERDATE)

它的投掷错误为未知列'SKU'

表格说明

 Name Type Collation Attributes Null Default Extra
1 ID varchar(36) utf8_general_ci No None
2 InvoiceNo varchar(20) utf8_general_ci No None
3 RefRetailer varchar(36) utf8_general_ci No None
4 SKU varchar(20) utf8_general_ci No None
5 OrderDate date No None
6 CurrentStatus varchar(10) utf8_general_ci No None
7 Price double No None
8 PaymentType varchar(10) latin1_swedish_ci No None

3 个答案:

答案 0 :(得分:2)

我没有看到一个内连接,而是一个dinamically创建的临时表,并在此 你没有列sku

可能还需要子选择中的SKU

SELECT ORDER_MONTH,
SUM(PRICE) as Price    
FROM  ( SELECT SKU,
               EXTRACT(YEAR FROM ORDERDATE) AS ORDER_YEAR,    
               MONTHNAME(ORDERDATE) AS ORDER_MONTH,        
               ORDERDATE, 
               PRICE  
      FROM ORDER_ABSTRACT) A
WHERE ORDER_YEAR=2016 
AND SKU='4567' 
GROUP BY MONTH(ORDERDATE)

答案 1 :(得分:1)

我不知道需要子查询 - 您可以重写下面的某些内容

SELECT  case
                when month(orderdate) = 1 then 'Jan'
                when month(orderdate) = 2 then 'Feb'
                when month(orderdate) = 3 then 'Mar'
                when month(orderdate) = 4 then 'Apr'
                when month(orderdate) = 5 then 'May'
                when month(orderdate) = 6 then 'Jun'
                when month(orderdate) = 7 then 'Jul'
                when month(orderdate) = 8 then 'Aug'
                when month(orderdate) = 9 then 'Sep'
                when month(orderdate) = 10 then 'Oct'
                when month(orderdate) = 11 then 'Nov'
                when month(orderdate) = 12 then 'Dec'
            end ordermonth
                ,SUM(PRICE) as Price    
FROM    order_abstract
WHERE   year(ORDERdate) = 2016 AND SKU=4567 
GROUP BY MONTH(ORDERDATE);

答案 2 :(得分:0)

private void rootStackPanel_Loaded(object sender, RoutedEventArgs e)
{
    TransitionCollection trs = new TransitionCollection();
    EntranceThemeTransition enttrs = new EntranceThemeTransition()
    {
        FromVerticalOffset = 600
    };
    trs.Add(enttrs);
    rootStackPanel.ChildrenTransitions = trs;
}

这解决了我的问题。