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 | 正文 |
年季度 | 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 注:其中where 1=1 表示條件永真,防止沒有之後的參數條件時,where多出而導致出錯。 | 正文 |