Как конвертировать код SQL в формат Grafana - PullRequest
0 голосов
/ 17 апреля 2019

У меня есть SQL-запрос, который мне нужно помочь с преобразованием в формат Grafana. Я попытался преобразовать код в Grafana, но он дает мне и неизвестный макрос _timeEpoch ошибка. Я не знаю, является ли преобразование неправильным или есть настройки в Графане, которые мне нужно изменить.

Вот что пытался сделать:

select 
$_timeEpoch(CAST(MONTH(B.invoice_date) AS varchar(2)) + '-' + RIGHT('0' + CAST(DAY(B.invoice_date) AS varchar(2)), 2) + '-' + CAST(YEAR(B.invoice_date)AS varchar(4))),
'$'+ Format(SUM(B.total_amount), '#,00') as value
from invoice_hdr as B
join oe_pick_ticket as A on A.invoice_no = B.invoice_no
Where 
$_timeFilter(invoice_date >= DATEADD(DAY, DATEDIFF(DAY, 7, GETDATE()), 0) and approved = 'Y' and (location_id = '10' 
or location_id = '11' 
or location_id = '12'
or location_id = '13' 
or location_id = '14'
or location_id = '15' 
or location_id = '20'
or location_id = '25' 
or location_id = '30'
or location_id = '40' 
or location_id = '50'))
GROUP by CAST(MONTH(B.invoice_date) AS varchar(2))+ '-' + RIGHT('0' + CAST(DAY(B.invoice_date) AS varchar(2)), 2) + '-' + CAST(YEAR(B.invoice_date)AS varchar(4)) 
Order by 
CAST(MONTH(B.invoice_date) AS varchar(2))+ '-' + RIGHT('0' + CAST(DAY(B.invoice_date) AS varchar(2)), 2) + '-' + CAST(YEAR(B.invoice_date)AS varchar(4)) ASC

Вот код SQL:

select CAST(MONTH(B.invoice_date) AS varchar(2)) + '-' + RIGHT('0' + CAST(DAY(B.invoice_date) AS varchar(2)), 2) + '-' + CAST(YEAR(B.invoice_date)AS varchar(4)) AS 'Invoice Date', '$'+ Format(SUM(B.total_amount), '#,00') as 'Total Amount'
from invoice_hdr as B
join oe_pick_ticket as A on A.invoice_no = B.invoice_no
Where invoice_date >= DATEADD(DAY, DATEDIFF(DAY, 7, GETDATE()), 0) and approved = 'Y' and (location_id = '10' 
or location_id = '11' 
or location_id = '12'
or location_id = '13' 
or location_id = '14'
or location_id = '15' 
or location_id = '20'
or location_id = '25' 
or location_id = '30'
or location_id = '40' 
or location_id = '50') 
GROUP by CAST(MONTH(B.invoice_date) AS varchar(2))+ '-' + RIGHT('0' + CAST(DAY(B.invoice_date) AS varchar(2)), 2) + '-' + CAST(YEAR(B.invoice_date)AS varchar(4)) 
order by 'Invoice Date'

Формат, в котором я нуждаюсь:

SELECT
  $__timeEpoch(<time_column>),
  <value column> as value,
  <series name column> as metric
FROM
  <table name>
WHERE
  $__timeFilter(time_column)
ORDER BY
  <time_column> ASC
...