select ${"'"+switch(p_dimension, 4, TO_CHAR(CONCATENATE(p_year,"-",p_sj),'yyyy-MM'), 3,switch(p_sj, "一季度", CONCATENATE(p_year-1,"-","10"), "二季度", CONCATENATE(p_year,"-","01"), "三季度", CONCATENATE(p_year,"-","04"), "四季度", CONCATENATE(p_year,"-","07"), ) , 2,if(p_sj="上半年",CONCATENATE(p_year-1,"-","07"),CONCATENATE(p_year,"-","01")), 1,CONCATENATE(p_year,"-","01") )+"'"} as start_month
时间: 2023-08-07 12:13:05 浏览: 149
您的SQL查询中使用了一个switch语句来选择不同的条件。根据您提供的维度(p_dimension)和时间段(p_sj),switch语句会返回不同的开始月份。以下是根据您提供的条件生成的开始月份的示例:
```sql
SELECT
CASE
WHEN p_dimension = 4 THEN TO_CHAR(CONCATENATE(p_year,"-",p_sj),'yyyy-MM')
WHEN p_dimension = 3 THEN
CASE p_sj
WHEN "一季度" THEN CONCATENATE(p_year-1,"-","10")
WHEN "二季度" THEN CONCATENATE(p_year,"-","01")
WHEN "三季度" THEN CONCATENATE(p_year,"-","04")
WHEN "四季度" THEN CONCATENATE(p_year,"-","07")
END
WHEN p_dimension = 2 THEN
CASE p_sj
WHEN "上半年" THEN CONCATENATE(p_year-1,"-","07")
ELSE CONCATENATE(p_year,"-","01")
END
ELSE CONCATENATE(p_year,"-","01")
END AS start_month;
```
请注意,此代码仅为示例,具体的语法和函数可能因数据库类型而异。确保根据您的数据库类型进行相应的调整。
阅读全文