Hi, I’m new to grafana and I find some problems when I’m using grafana. I’m using Grafana v7.4.3 and When I’m using variable query in my panel, the outcome didn’t show anything. This is my query
SELECT
created_at AS “time”,
left(sku,2) AS metric,
sum(qty) AS “Quanity”,
count(id) AS “Moving number”
FROM MY_DB
WHERE
$__timeFilter(created_at) and sku LIKE"$SKU%"
GROUP BY left(sku,2)
ORDER BY created_at
AND THIS IS MY VARIABLE QUARY
select LEFT(sku,2) from MY_DB
I watched Generated SQL and find this
created_at BETWEEN FROM_UNIXTIME(1624285135) AND FROM_UNIXTIME(16243067359 and LEFT(sku,2) LIKE"‘SM’%". So, how can I remove ’ from “‘SM’%”? Thx
can you tidy up the code a little bit so we can read it better?
because , you said this is your query
SELECT
created_at AS “time”,
left(sku,2) AS metric,
sum(qty) AS “Quanity”,
count(id) AS “Moving number”
FROM MY_DB
WHERE
$__timeFilter(created_at) and sku LIKE"$SKU%"
GROUP BY left(sku,2)
ORDER BY created_at
and this is the generated SQL
created_at BETWEEN FROM_UNIXTIME(1624285135) AND FROM_UNIXTIME(16243067359 and LEFT(sku,2) LIKE"‘SM’%"
that doesnt make sense
- missing close bracket for FROM_UNIXTIME(16243067359
- suddenly there is LEFT(sku,2) LIKE when your query only has sku LIKE
maybe copy everything from your query
and the generated SQL?
–
if I get your point correctly, in your query, you want to filter data using the variable $SKU
so what about using this
WHERE $__timeFilter(created_at) AND LEFT(SKU,2) = $SKU
no need to use LIKE
well, I think that solve my problem,thanks and next time I will tidy up my code title! Thx!
cool cool ,
any time
This topic was automatically closed after 365 days. New replies are no longer allowed.