1. 概述编辑
本文提供 实时数据 使用 SQL 数据集参数的 SQL 写法示例。
注:不同数据库的写法不同,本文仅提供参考示例。
2. 日期类参数编辑
日期类型 | SQL 示例 | 推荐设置的参数类型 |
---|---|---|
年份 | select * from new_salesdetail where year(销售日期)='${年份}' | 文本 |
年月 | select * from new_salesdetail where year(销售日期)='${年份}' and month(销售日期)='${月份}' | 文本 |
日期 | select * from new_salesdetail where 销售日期 in ('${日期}') | 日期 |
日期区间 | select * from new_salesdetail where 销售日期 between '${起始日期}' and '${结束日期}' | 日期 |
年月区间 | select * from DEMO_CONTRACT where 注册时间 >= PARSEDATETIME('${开始年份}'||'-'||0||'${开始月份}'||'-'||'01','yyyy-MM-dd') and 注册时间 <PARSEDATETIME('${截至年份}'||'-'||0||'${截至月份}'+1||'-'||'01','yyyy-MM-dd') 或者: SELECT * FROM 互联网_访问统计表 WHERE 1=1 <parameter> and TO_CHAR("统计日期",'yyyymm') >=concat('${开始年份}',case when cast('${开始月份}' as tinyint)>9 then '${开始月份}' else concat('0','${开始月份}') end ) and TO_CHAR("统计日期",'yyyymm') <=concat('${截至年份}',case when cast('${截至月份}' as tinyint)>9 then '${截至月份}' else concat('0','${截至月份}') end )</parameter> | 文本 |
年季度 | select * from DEMO_CONTRACT where year(注册时间) = '${年份}' and (month(注册时间)+2)/3 = '${季度}' | 文本 |
3. 文本类参数编辑
文本类型 | SQL 示例 | 推荐设置的参数类型 |
---|---|---|
参数只能取一个值 | select * from demo_contract where 合同类型='${文本参数}' | 文本 |
参数可以取多个值 | select * from demo_contract where 合同类型 in ('${文本参数}') | 文本 |
当参数为空时,显示全部,参数有值时,显示参数值 | select * from new_dian where 1=1 ${if(len(所属大区2) == 0,"","and 所属大区 in ('" + 所属大区2 + "')")} 或者:select * from new_dian where 1=1 <parameter> and 所属大区 in ('${所属大区}')</parameter> 注:其中where 1=1 表示条件永真,防止没有之后的参数条件时,where多出而导致出错。 | 文本 |