利用sql控制参数的入门使用
FineBI 允许使用模板语法(如 、 {}、 、{if(…)}、${switch(…)} 等)来动态生成 SQL 查询。
1. ${}的使用
类似,python、C语言中的定义参数,通过用户输入进行传参,更加灵活
SELECT * FROM sales
WHERE sale_date BETWEEN '${startDate}' AND '${endDate}'
如果用户选择了 2023-01-01 到 2023-01-31,那么生成的 SQL 查询可能是:
SELECT * FROM sales
WHERE sale_date BETWEEN '2023-01-01' AND '2023-01-31'
2. switch的使用
switch(条件,
值1, 结果1,
值2, 结果2,
...,
默认值, 默认结果)
- 条件:这是要判断的表达式或变量
switch(userRole,
'admin', 'SELECT * FROM admin_data',
'user', 'SELECT * FROM user_data',
'guest', 'SELECT * FROM guest_data'
)
3."&&"的使用
- 字符串型
字符串型须在名字两边要加单引号,数值型可以不加
nsertintousertable(username) values( '小小')
如果现在姓名是一个变量thename,则写成:
Insertintousertable(username) values( '" & thename & "')
ps:&改为+号也可以,字符串连接
- 数字型
假如插入一个年龄为12的记录,要注意数字不用加单引号
Insertintousertable(age) values( 12)
如果现在年龄是一个变量theage,则为:
Insertintousertable(age) values(“ & theage & “)
4.可视化绑定参数
在报表界面绑定sql中的参数