Advertisement
Advertisement

新足迹

 找回密码
 注册
新足迹 门户 IT专业论坛 查看内容

呼叫MS ACCESS高手,group by 为啥不能用alias name

2010-8-5 13:52| 发布者: jl162401 | 查看: 1768| 原文链接

SELECT
a.material_code
,year(a.Consumption_Date)  
,month(a.Consumption_Date)  
,sum(a.consumption_qty) as sum0
,sum(nz(b.quantity,0)) as sum1
,(sum0 - sum1)
,(IIF(IsNULL(c.material),' ','Scrapped')) as flg
from ( SAP_Consumption a
left join
SMOG_Special_Sales b
on a.material_code  = cstr(b.code)
and month(a.Consumption_Date) = month(b.Delivery_Date)
and year(a.Consumption_Date) = year(b.Delivery_Date) )
left join (select distinct material from Scrapped_Blocked_list
where code_blocked_C1 = 'Y') c
on a.material_code = c.material
GROUP BY material_code
,year(a.Consumption_Date)
,month(a.Consumption_Date)
,flg

这样运行会报错
"You tried to execute a query that does not include the specified expression <name> as part of an aggregate function. (Error 3122)"

但是如果我把(IIF(IsNULL(c.material),' ','Scrapped')) 直接放在Group by里面,是可以得到正确结果

SELECT
a.material_code
,year(a.Consumption_Date)  
,month(a.Consumption_Date)  
,sum(a.consumption_qty) as sum0
,sum(nz(b.quantity,0)) as sum1
,(sum0 - sum1)
,(IIF(IsNULL(c.material),' ','Scrapped')) as flg
from ( SAP_Consumption a
left join
SMOG_Special_Sales b
on a.material_code  = cstr(b.code)
and month(a.Consumption_Date) = month(b.Delivery_Date)
and year(a.Consumption_Date) = year(b.Delivery_Date) )
left join (select distinct material from Scrapped_Blocked_list
where code_blocked_C1 = 'Y') c
on a.material_code = c.material
GROUP BY material_code
,year(a.Consumption_Date)
,month(a.Consumption_Date)
,(IIF(IsNULL(c.material),' ','Scrapped'))

为何不能用alias name在group by 里面 ?

谁有MS ACCESS的SQL语法大全啊,能否share一下,多谢多谢
Advertisement
Advertisement


Advertisement
Advertisement
返回顶部