关于if的数据集语句语法错误,不知道哪里错了

SELECT * FROM XIAOHAO  where    ${
IF(AND(aa >= YEAR(aa) + "-" + "01-01",aa <= YEAR(aa) + "-" + "01-29"),

"and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "01"+ "'",


IF(AND(aa >= YEAR(aa) + "-" + "01-30", aa <= IF(YEAR(aa) % 400 = 0, YEAR(aa) + "-" + "02-27", IF(YEAR(aa) % 4 = 0, YEAR(aa) + "-" + "02-27", YEAR(aa) + "-" + "02-26"))),

"and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "02"+ "'",


IF(AND(aa > IF(YEAR(aa) % 400 = 0, YEAR(aa) + "-" + "02-27", IF(YEAR(aa) % 4 = 0, YEAR(aa) + "-" + "02-27", YEAR(aa) + "-" + "02-26")), aa <= YEAR(aa) + "-" + "03-29"),
"and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "03"+ "'",

IF(AND(aa >= YEAR(aa) + "-" + "03-30", aa <= YEAR(aa) + "-" + "04-28"), "and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "04"+ "'",
 IF(AND(aa >= YEAR(aa) + "-" + "04-29", aa <= YEAR(aa) + "-" + "05-29"), "and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "05"+ "'",
 IF(AND(aa >= YEAR(aa) + "-" + "05-30", aa <= YEAR(aa) + "-" + "06-28"), "and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "06"+ "'",
 IF(AND(aa >= YEAR(aa) + "-" + "06-29", aa <= YEAR(aa) + "-" + "07-29"), "and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "07"+ "'",
 IF(AND(aa >= YEAR(aa) + "-" + "07-30", aa <= YEAR(aa) + "-" + "08-29"),"and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "08"+ "'",
 IF(AND(aa >= YEAR(aa) + "-" + "08-30", aa <= YEAR(aa) + "-" + "09-28"),"and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "09"+ "'",
 IF(AND(aa >= YEAR(aa) + "-" + "09-29", aa <= YEAR(aa) + "-" + "10-29"), "and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "10"+ "'",
 IF(AND(aa >= YEAR(aa) + "-" + "10-29", aa <= YEAR(aa) + "-" + "11-28"), "and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "11"+ "'",
 IF(AND(aa >= YEAR(aa) + "-" + "11-29", aa <= YEAR(aa) + "-" + "12-31"), "and createdate<='"+aa+"'"+"and yuefen='"+YEAR(aa) + "-" + "12"+ "'",
 100))))))))))))



} order by createdate

FineReport 张宇 发布于 2018-11-23 15:15 (编辑于 2018-11-23 15:39)
1min目标场景问卷 立即参与
回答问题
悬赏:5 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
1
cherishdqyLv7高级互助
发布于2018-11-23 15:24(编辑于 2018-11-23 15:24)
SELECT * 
FROM XIAOHAO    
where 1=1  
${IF(AND(aa >= YEAR(aa) + "-" + "01-01",aa <= YEAR(aa) + "-" + "01-29")," and createdate<='"+aa+"'"+" and yuefen='"+YEAR(aa) + "-" + "01"+ "'","")} 
order by createdate

少了and和空格

  • 张宇 张宇(提问者) SELECT * FROM XIAOHAO where ${ IF(AND(aa >= YEAR(aa) + \"-\" + \"01-01\",aa <= YEAR(aa) + \"-\" + \"01-29\"), \"and createdate<=\'\"+aa+\"\'\"+\"and yuefen=\'\"+YEAR(aa) + \"-\" + \"01\"+ \"\'\", IF(AND(aa >= YEAR(aa) + \"-\" + \"01-30\", aa <= IF(YEAR(aa) % 400 = 0, YEAR(aa) + \"-\" + \"02-27\", IF(YEAR(aa) % 4 = 0, YEAR(aa) + \"-\" + \"02-27\", YEAR(aa) + \"-\" + \"02-26\"))), YEAR(aa) + \"-\" + \"02\", IF(AND(aa > IF(YEAR(aa) % 400 = 0, YEAR(aa) + \"-\" + \"02-27\", IF(YEAR(aa) % 4 = 0, YEAR(aa) + \"-\" + \"02-27\", YEAR(aa) + \"-\" + \"02-26\")), aa <= YEAR(aa) + \"-\" + \"03-29\"), YEAR(aa) + \"-\" + \"03\", IF(AND(aa >= YEAR(aa) + \"-\" + \"03-30\", aa <= YEAR(aa) + \"-\" + \"04-28\"), YEAR(aa) + \"-\" + \"04\", IF(AND(aa >= YEAR(aa) + \"-\" + \"04-29\", aa <= YEAR(aa) + \"-\" + \"05-29\"), YEAR(aa) + \"-\" + \"05\", IF(AND(aa >= YEAR(aa) + \"-\" + \"05-30\", aa <= YEAR(aa) + \"-\" + \"06-28\"), YEAR(aa) + \"-\" + \"06\", IF(AND(aa >= YEAR(aa) + \"-\" + \"06-29\", aa <= YEAR(aa) + \"-\" + \"07-29\"), YEAR(aa) + \"-\" + \"07\", IF(AND(aa >= YEAR(aa) + \"-\" + \"07-30\", aa <= YEAR(aa) + \"-\" + \"08-29\"), YEAR(aa) + \"-\" + \"08\", IF(AND(aa >= YEAR(aa) + \"-\" + \"08-30\", aa <= YEAR(aa) + \"-\" + \"09-28\"), YEAR(aa) + \"-\" + \"09\", IF(AND(aa >= YEAR(aa) + \"-\" + \"09-29\", aa <= YEAR(aa) + \"-\" + \"10-29\"), YEAR(aa) + \"-\" + \"10\", IF(AND(aa >= YEAR(aa) + \"-\" + \"10-29\", aa <= YEAR(aa) + \"-\" + \"11-28\"), YEAR(aa) + \"-\" + \"11\", IF(AND(aa >= YEAR(aa) + \"-\" + \"11-29\", aa <= YEAR(aa) + \"-\" + \"12-31\"), YEAR(aa) + \"-\" + \"12\", 100)))))))))))) } order by createdate 这个长的该咋写
    2018-11-23 15:29 
  • cherishdqy cherishdqy 回复 张宇(提问者) 你这是啥。。。用完善问题,不要在这里回复这个sql
    2018-11-23 15:30 
  • 张宇 张宇(提问者) 回复 cherishdqy 完善完了 大神帮忙看看吧
    2018-11-23 15:34 
  • cherishdqy cherishdqy 回复 张宇(提问者) 你后面那一串if是要干嘛啊
    2018-11-23 15:40 
  • 张宇 张宇(提问者) 回复 cherishdqy 按照你的格式又重新 编辑了一下问题,写了一下 还是不对 指点一下吧
    2018-11-23 15:40 
最佳回答
0
zexalLv3见习互助
发布于2018-11-23 15:28

createdate前面是不是少了一个and 

最佳回答
0
轩辕丶尘Lv2初级互助
发布于2018-11-23 15:29

你的需求是什么呢?如果前边满足你要干啥?中间语句的引号好好查一下吧

  • 4关注人数
  • 1392浏览人数
  • 最后回答于:2018-11-23 15:39
    请选择关闭问题的原因
    确定 取消
    返回顶部