Combining JQL and SQL


Please, read about AUX.JQL function which allows you to use JQL inside SQL.

Enhancing JQL queries with SQL features

Having a JQL query or filter can be transformed to more informative data by using SmartQL SQL features. First of all - you can apply aggregates onto you JQL quey, see example:

SELECT issuetype, status, COUNT(issuekey), MIN(created), MAX(updated)
FROM TABLE(AUX.JQL('issuetype,status,issuekey,created,updated', 'project = SSP'))
GROUP BY issuetype, status

This query treats issues foung from JQL 'project = SSP' as a table with columns 'issuetype,status,issuekey,created,updated'. Example results can be following:

issuetypestatusEXPR$2EXPR$3EXPR$4
100011000182018-06-12 13:38:352018-07-08 00:18:35
100011000082018-07-09 14:42:352018-07-10 18:52:38
10101322018-07-06 21:44:352018-07-07 19:09:35
10001312018-07-03 09:42:352018-07-03 09:42:35
101021000112018-07-03 09:42:352018-07-07 02:18:35
101011000012018-07-10 18:52:372018-07-10 18:52:37
101021000022018-07-03 09:42:352018-07-10 18:52:38

For converting your Jira searches and any JQL you can start with Jira builtin navigator and then export prepared JQL query to SmartQL, see Exporting issue searches & JQL queries to SmartQL

Joining JQL data with other SQL views available in SmartQL

Result of JQL queries can be joined with views and tables from SmartQL. Previous example query can be updated:

SELECT it.NAME `Issue type`, s.NAME `Status`, COUNT(issuekey), MIN(created), MAX(updated)
FROM TABLE(AUX.JQL('project, issuetype,status,issuekey,created,updated', 'project = SSP')) j
JOIN ISSUETYPES it ON it.ID = j.issuetype
JOIN STATUSES s on s.ID = j.status
GROUP BY it.NAME, s.NAME

Example results can be following:

Issue typeStatusEXPR$2EXPR$3EXPR$4
Sub-taskTo Do12018-07-10 18:52:372018-07-10 18:52:37
StoryDone82018-06-12 13:38:352018-07-08 00:18:35
StoryTo Do82018-07-09 14:42:352018-07-10 18:52:38
Sub-taskIn Progress22018-07-06 21:44:352018-07-07 19:09:35
BugDone12018-07-03 09:42:352018-07-07 02:18:35
BugTo Do22018-07-03 09:42:352018-07-10 18:52:38
StoryIn Progress12018-07-03 09:42:352018-07-03 09:42:35

Lateral joining JQL with SQL

JQL queries can also be computed for each row of other table or view, by using lateral joins.  Following query shows first 5 agile board to issue mappings.

SELECT b.NAME, j.key
FROM SOFTWARE.BOARDS b
JOIN CORE.FILTERS f on f.ID = b.SAVEDFILTER
CROSS JOIN LATERAL TABLE(AUX.JQL('key', f.query)) j
LIMIT 5

Example result:

NAMEkey
SSP boardSSP-1
SSP boardSSP-2
SSP boardSSP-3
SSP boardSSP-4
SSP boardSSP-5

Using quotes across JQL and SQL in one query

Double quotes " are for JQL strings.

Single quotes ' are for SQL strings.

Backquotes ` are for boundaries of SQL columns names.