Table

It works similarly to the SQL for JIRA Value table. It has also to be defined in the Custom Field Description, just the same SQL query is shared among all the issues and the users cannot modify them.

Given a SQL for JIRA query, the ? symbol is replaced with the contextual issue key and all the columns in the SELECT clause will be displayed on the Issue's custom field.

Example:


select w.author as "User" , FORMATDURATION(sum(w.timespent),true) as "Effort"
from issues i inner join issueworklogs w on w.issueid=i.id
where i.key = ? group by w.author



Example

Suppose our issues are divided into subtask of different types and we are interested in knowing how many subtasks there are of each type. This can be achieved with "SQL for JIRA Table" custom field.


The first step is to create the query to get the values that we want to display, and for this we help from the SQL for JIRA Driver.

We open the SQL for JIRA Driver console and build our sql:



We get the following sql:

Counter of types of subtasks in a issue
SELECT isd.NAME AS "Type Subtask", count(*) as "Num Subtask"
   FROM ISSUES i2, issuetypedefinitions isd
   WHERE i2.id in (
      SELECT isb.SUBTASKID
      FROM issues i
      INNER JOIN issuesubtasks isb ON i.id = isb.PARENTID
      WHERE  i.jql='issue=${key}' 
      ) 
     AND isd.ID = i2.TYPEID 
GROUP BY isd.name
ORDER BY isd.name ASC

Change Issue Identifier

As can be seen, the query of the image has been made for a particular issue, in this case the issue with identifier 10701. But we want to calculate the number of subtask types for the issue that is being displayed in JIRA at that time. Therefore, we need to take the key of the issue as a variable. For this, we replace the identifier 10701 with the expression ${key}. The add-on is smart enough to replace the value of the expression with the identifier of the issue being displayed.


Obtaining the sql, we created a custom field of type SQL for JIRA Table and we insert our sql in the description of the custom field:


With these simple steps, we already have our custom field that number of subtask types in a issue.



As you can see, it is easy to use the custom field, you just have to get the appropriate SQL for the information that we want to display.
We can show any information that we imagine, and this is the great potential of the custom field, we just need to create a query and the custom field will take care of the rest.