在查询分析器中这个语句可以用:
 SELECT DISTINCT t_caig.material_id AS pn, avg(Case t_caig.curency_calssfy when 'USD' then t_caig.unit_price*8.041 when 'RMB' then t_caig.unit_price when 'NTD' then t_caig.unit_price/4  else 0 end) as pj 
FROM t_caption INNER JOIN t_caig ON t_caption.indent_id = t_caig.indent_id 
WHERE (t_caption.indent_date BETWEEN '2006-3-1' AND '2006-3-31')
GROUP BY t_caig.material_id但在access 中Case语句不能用,有什么函数语句可以在acess中代替sqlserve中的case呢, 我的access知道的很少,请大家帮帮忙!!

解决方案 »

  1.   

    SELECT DISTINCT dbo_t_caig.material_id, Avg(iif(dbo_t_caig.curency_classfy ='USD',dbo_t_caig.unit_price*8.041,iif(dbo_t_caig.curency_classfy ='NTD',dbo_t_caig.unit_price/4,iif(IsNull(dbo_t_caig.curency_classfy),0,dbo_t_caig.unit_price))))AS unit_price
    FROM dbo_t_caig INNER JOIN dbo_t_caption ON dbo_t_caig.indent_id = dbo_t_caption.indent_id
    WHERE (((dbo_t_caption.indent_date) Between #3/1/2006# And #3/31/2006#))
    GROUP BY dbo_t_caig.material_id;xeqtr1982(ShaKa),谢谢你,但这样出来的unit_price单价是乱码,而且还出现一个让输入币种的对话框
      

  2.   

    eg:
    SQL:
    select bb,cc,case aa when '一星级' then '*'
    when '二星级' then '** '
    when '三星级' then '*** '
    when '四星级' then '**** '
    when '五星级' then '***** '
    end
    from aaa----------------------
    Access:select  bb,cc,iif(aa='一星级','*',iif(aa='二星级','**',iif(aa='三星级','***',iif(aa='四星级','****',iif(aa='五星级','*****')))))
    from aaa;
      

  3.   

    我要的是单价的平均值,我把Avg()函数加上去,怎么就不能分类汇总了?,而且出现不了和sql中的正确结果,找不出原因
      

  4.   

    你可以去access版问问。手里没有数据,不太好测试