我正在使用与Mysql集成的配置数据库来进行报告。我浏览了文档,但无法找到任何解释如何在基于SQL的问题中实现过滤器的示例。
我发现的唯一例子是关于日期范围和字段过滤器,而不是文本和数字。
任何人都可以提供有关如何使用文本过滤器的文档或任何示例。
我正在使用配置数据库版本v0.24.2
我正在尝试运行的查询是
SELECT @a:=@a+1 "Serial Number", ssk_transaction.transactionId AS "TranId", t2.typeName AS "Transaction Type", ssk_transaction.createdTime AS "GenDate", t3.deviceName AS "Machine Name", t3.deviceLocation AS "Machine Location", t9.eventApiName AS 'API Name' , t8.vendorResultCode AS 'Last API Response', (SELECT createdTime FROM ssk_transaction_event_detail t4 WHERE t4.transactionId = ssk_transaction.transactionId ORDER BY id DESC LIMIT 1) AS "Last API Called", (SELECT IFNULL(SUM(t5.itemName * t4.itemCount), 0) FROM ssk_transaction_cash_detail t4 LEFT JOIN ssk_inventory_item t5 ON (t4.itemId = t5.itemId) LEFT JOIN ssk_inventory_category t10 ON (t5.categoryId = t10.categoryId) WHERE t4.transactionId = ssk_transaction.transactionId AND t10.categoryName = 'acceptor') "Cash In", (SELECT IFNULL(SUM(t5.itemName * t4.itemCount), 0) FROM ssk_transaction_cash_detail t4 LEFT JOIN ssk_inventory_item t5 ON (t4.itemId = t5.itemId) LEFT JOIN ssk_inventory_category t10 ON (t5.categoryId = t10.categoryId) WHERE t4.transactionId = ssk_transaction.transactionId AND t10.categoryName = 'dispenser') "Cash Returned", IFNULL((SELECT "Cash In"), 0) - IFNULL((SELECT "Cash Returned"), 0) AS "Amount of Activity", (SELECT t8.vendorResultCode FROM ssk_transaction_event_detail t8 WHERE t8.transactionId = ssk_transaction.transactionId AND t8.eventId = 6 ORDER BY id DESC LIMIT 1) AS "Sim Status", 'Completed' AS "Transaction Status", ssk_transaction.customerMsisdn AS MSISDN, ssk_transaction.customerCNIC AS CNIC FROM (SELECT @a:=0) initvars, ssk_transaction LEFT JOIN ssk_transaction_type t2 ON (ssk_transaction.typeId = t2.typeId) LEFT JOIN ssk_device t3 ON (ssk_transaction.deviceUUID = t3.deviceUUID) LEFT JOIN ssk_transaction_cash_detail t6 ON (ssk_transaction.transactionId = t6.transactionId ) LEFT JOIN ssk_inventory_item t7 ON (t6.itemId = t7.itemId) LEFT JOIN ssk_transaction_event_detail t8 ON (ssk_transaction.transactionId = t8.transactionId AND t8.eventId = 10) LEFT JOIN ssk_transaction_event t9 ON (t9.eventId = t8.eventId) WHERE {{created_at}} AND {{id}} [[AND ssk_transaction.customerMsisdn= {{msisdn}}]] AND {{cnic}} and t2.typeId = 3 AND t8.eventId = 10 AND t8.vendorResultCode = '405000000' GROUP BY ssk_transaction.transactionId ORDER BY ssk_transaction.createdTime ASC
答案 0 :(得分:4)
在您正在使用的版本号下的 github 页面上打开一个问题。 贡献者将帮助您查询或甚至提供所需的文档/ wiki。
也许这可以帮到你:
try to use CONCAT('%',{{variable}},'%') such as:
WHERE 1=1 [[ AND test LIKE CONCAT('%',{{variable}},'%') ]]
答案 1 :(得分:2)
要创建变量,只需编写查询并以{{variablename}}格式为变量定义占位符,当您执行此操作时,Metabase将自动显示右侧的“变量”面板,您必须选择此变量的类型(如果提供默认值,也可以根据需要标记变量。)
您不应该在查询中转义变量占位符(这就是为什么CONCAT('%',{{variable}},'%')不起作用的原因)您可以使用双括号将整个表达式标记为可选项。
下面的图片给出了一个查询示例:
从pg_tables中选择*,其中schemaname = {{schemaname}} [[and tablename = {{tablename}}]]
在此示例中,如果您没有为tablename变量提供值,则将忽略整个tablename过滤器。请注意,两个变量都标有文本类型。
答案 2 :(得分:1)
要在基于sql的(本机查询)问题上添加过滤器,请在生成sql结果后,单击右下角的罗盘,然后单击“分析此查询的结果”。过滤器选项将显示在顶部。
然后您可以将其另存为其他问题,以便始终显示过滤器屏幕。