日期:2014-05-16  浏览次数:20900 次

关于一段sql 语法
SQL code
SELECT SUM(CASE WHEN xf_reverse = 'N'  THEN xf_incount  ELSE xf_outcount  END) groupincount,

 SUM(CASE WHEN xf_reverse = 'Y' THEN xf_incount ELSE xf_outcount END) groupoutcount, 

xf_storecode storecode, xf_startyear starty, xf_startmonth startm, xf_startday startd FROM

 (SELECT xf_storecode, xf_startyear, xf_startmonth, xf_startday FROM xf_tc_countdata   cd STRAIGHT_JOIN

(SELECT * FROM xf_tc_mapping WHERE 1 = 1 AND (1 = 0 OR xf_storecode = '001000') AND (1 = 0 OR xf_zoneid = '00')) map ON 

cd.xf_machineid = map.xf_machineid AND cd.xf_cameraid = map.xf_cameraid WHERE 1 = 1 AND 

{FN CONCAT({FN CONCAT({FN CONCAT({FN CONCAT(xf_startyear, '-')}, xf_startmonth)}, '-')},xf_startday)} >= '2009-04-01' AND

 {FN CONCAT({FN CONCAT({FN CONCAT({FN CONCAT(xf_endyear, '-')}, xf_endmonth)}, '-')},xf_endday)} <= '2009-04-20' AND 

{FN CONCAT(xf_starthour, xf_startminute)} >= '0000' AND {FN CONCAT(xf_starthour, xf_startminute)} < '2400' 

GROUP BY xf_storecode, xf_startyear, xf_startmonth, xf_startday ) countdata  

GROUP BY xf_storecode, xf_startyear, xf_startmonth, xf_startday



为什么说没有 xf_reverse 字段??是作用域不对吗? HELP

------解决方案--------------------
检查表中是否有xf_reverse字段,子查询中是否有xf_reverse字段