Created
September 25, 2015 20:58
-
-
Save spscream/93cccaaf81b386ba2cc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
'actualizator' AS comment_type, | |
wo.ID AS workorder_id, | |
comments.ID AS id, | |
comments.Comments AS comment, | |
comments.Date AS DATE, | |
author.ID AS author_id, | |
author.FullName AS author_fullname | |
FROM WorkOrderActualizatorComments AS comments | |
INNER JOIN WorkOrderActualizator AS actualizator ON comments.WorkOrderActualizatorId = actualizator.Id | |
INNER JOIN WorkOrder AS wo ON wo.ID = actualizator.WorkOrderID | |
INNER JOIN "User" AS author ON actualizator.ActualizatorID = author.ID | |
UNION | |
SELECT | |
'coordinator' AS comment_type, | |
wo.ID AS workorder_id, | |
comments.ID AS id, | |
comments.Comments AS comment, | |
comments.Date AS DATE, | |
author.ID AS author_id, | |
author.FullName AS author_fullname | |
FROM WorkOrderCoordinatorComments AS comments | |
INNER JOIN WorkOrderCoordinator AS coordinator ON comments.WorkOrderCoordinatorId = coordinator.Id | |
INNER JOIN WorkOrder AS wo ON wo.ID = coordinator.WorkOrderID | |
INNER JOIN "User" AS author ON coordinator.CoordinatorID = author.ID | |
UNION | |
SELECT | |
'executor' AS comment_type, | |
wo.ID AS workorder_id, | |
comments.ID AS id, | |
comments.Comments AS comment, | |
comments.Date AS DATE, | |
author.ID AS author_id, | |
author.FullName AS author_fullname | |
FROM WorkOrderExecutorComments AS comments | |
INNER JOIN WorkOrderExecutor AS executor ON comments.WorkOrderExecutorId = executor.Id | |
INNER JOIN WorkOrder AS wo ON wo.ID = executor.WorkOrderID | |
INNER JOIN "User" AS author ON executor.ExecutorID = author.ID | |
UNION | |
SELECT | |
'visator' AS comment_type, | |
wo.ID AS workorder_id, | |
comments.ID AS id, | |
comments.Comments AS comment, | |
comments.Date AS date, | |
author.ID AS author_id, | |
author.FullName AS author_fullname | |
FROM WorkOrderVisatorComments AS comments | |
INNER JOIN WorkOrderVisator AS visator ON comments.WorkOrderVisatorId = visator.Id | |
INNER JOIN WorkOrder AS wo ON wo.ID = visator.WorkOrderID | |
INNER JOIN "User" AS author ON comments.VisatorID = author.ID | |
UNION | |
SELECT | |
'validator' AS comment_type, | |
wo.ID AS workorder_id, | |
comments.ID AS id, | |
comments.Comments AS comment, | |
comments.Date AS date, | |
author.ID AS author_id, | |
author.FullName AS author_fullname | |
FROM WorkOrderValidatorComments AS comments | |
INNER JOIN WorkOrderValidator AS validator ON comments.WorkOrderValidatorId = validator.Id | |
INNER JOIN WorkOrder AS wo ON wo.ID = validator.WorkOrderID | |
INNER JOIN "User" AS author ON validator.ValidatorID = author.ID | |
ORDER BY date ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment