Skip to main content
adicionou 11 caracteres ao conteúdo
Fonte Link
João Martins
  • 5,7mil
  • 5
  • 16
  • 33
SELECT      YEAR(IFNULL(A.content_path, NOW()))                                                     AS anoAtual
        ,   MONTHNAME(M.Mes)                                                        AS Mes
        ,   TIME_FORMAT(SEC_TO_TIME(SUM(IFNULL(TA.time_unit, 0)) * 60), "%H:%i")    AS tempo_total
        ,   CONCAT(U.first_name, ' ', CU.last_name)                                 AS usuario
        ,   CU.email
FROM        (
                SELECT          1   AS Mes
                UNION SELECT    2   AS Mes
                UNION SELECT    3   AS Mes
                UNION SELECT    4   AS Mes
                UNION SELECT    5   AS Mes
                UNION SELECT    6   AS Mes
                UNION SELECT    7   AS Mes
                UNION SELECT    8   AS Mes
                UNION SELECT    9   AS Mes
                UNION SELECT    10  AS Mes
                UNION SELECT    11  AS Mes
                UNION SELECT    12  AS Mes
            ) AS M
INNERLEFT JOIN   article         A   ON  MONTH(A.content_path) = M.Mes
INNERLEFT JOIN   time_accounting TA  ON  TA.article_id               = A.id
INNERLEFT JOIN   users           U   ON  U.id                        = A.create_by
INNERLEFT JOIN   customer_user   CU  ON  CU.first_name               = U.first_name
                                AND CU.customer_id              = empresa
WHERE       EXTRACT(YEAR FROM A.content_path)   IN (2018)
        and U.last_name                         LIKE CONCAT(CU.last_name, '%')
        and U.valid_id                          = 1 
        and CU.email                            IN (emails)
GROUP BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
ORDER BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
SELECT      YEAR(A.content_path)                                                    AS anoAtual
        ,   MONTHNAME(M.Mes)                                                        AS Mes
        ,   TIME_FORMAT(SEC_TO_TIME(SUM(IFNULL(TA.time_unit, 0)) * 60), "%H:%i")    AS tempo_total
        ,   CONCAT(U.first_name, ' ', CU.last_name)                                 AS usuario
        ,   CU.email
FROM        (
                SELECT          1   AS Mes
                UNION SELECT    2   AS Mes
                UNION SELECT    3   AS Mes
                UNION SELECT    4   AS Mes
                UNION SELECT    5   AS Mes
                UNION SELECT    6   AS Mes
                UNION SELECT    7   AS Mes
                UNION SELECT    8   AS Mes
                UNION SELECT    9   AS Mes
                UNION SELECT    10  AS Mes
                UNION SELECT    11  AS Mes
                UNION SELECT    12  AS Mes
            ) AS M
INNER JOIN  article         A   ON  MONTH(A.content_path) = M.Mes
INNER JOIN  time_accounting TA  ON  TA.article_id               = A.id
INNER JOIN  users           U   ON  U.id                        = A.create_by
INNER JOIN  customer_user   CU  ON  CU.first_name               = U.first_name
                                AND CU.customer_id              = empresa
WHERE       EXTRACT(YEAR FROM A.content_path)   IN (2018)
        and U.last_name                         LIKE CONCAT(CU.last_name, '%')
        and U.valid_id                          = 1 
        and CU.email                            IN (emails)
GROUP BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
ORDER BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
SELECT      YEAR(IFNULL(A.content_path, NOW()))                                                     AS anoAtual
        ,   MONTHNAME(M.Mes)                                                        AS Mes
        ,   TIME_FORMAT(SEC_TO_TIME(SUM(IFNULL(TA.time_unit, 0)) * 60), "%H:%i")    AS tempo_total
        ,   CONCAT(U.first_name, ' ', CU.last_name)                                 AS usuario
        ,   CU.email
FROM        (
                SELECT          1   AS Mes
                UNION SELECT    2   AS Mes
                UNION SELECT    3   AS Mes
                UNION SELECT    4   AS Mes
                UNION SELECT    5   AS Mes
                UNION SELECT    6   AS Mes
                UNION SELECT    7   AS Mes
                UNION SELECT    8   AS Mes
                UNION SELECT    9   AS Mes
                UNION SELECT    10  AS Mes
                UNION SELECT    11  AS Mes
                UNION SELECT    12  AS Mes
            ) AS M
LEFT JOIN   article         A   ON  MONTH(A.content_path) = M.Mes
LEFT JOIN   time_accounting TA  ON  TA.article_id               = A.id
LEFT JOIN   users           U   ON  U.id                        = A.create_by
LEFT JOIN   customer_user   CU  ON  CU.first_name               = U.first_name
                                AND CU.customer_id              = empresa
WHERE       EXTRACT(YEAR FROM A.content_path)   IN (2018)
        and U.last_name                         LIKE CONCAT(CU.last_name, '%')
        and U.valid_id                          = 1 
        and CU.email                            IN (emails)
GROUP BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
ORDER BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
removeu 17 caracteres do conteúdo
Fonte Link
João Martins
  • 5,7mil
  • 5
  • 16
  • 33
SELECT      YEAR(A.content_path)                                                    AS anoAtual
        ,   MONTHNAME(M.Mes)                                                        AS Mes
        ,   TIME_FORMAT(SEC_TO_TIME(SUM(IFNULL(TA.time_unit, 0)) * 60), "%H:%i")    AS tempo_total
        ,   CONCAT(U.first_name, ' ', CU.last_name)                                 AS usuario
        ,   CU.email
FROM        (
                SELECT          1   AS Mes
                UNION SELECT    2   AS Mes
                UNION SELECT    3   AS Mes
                UNION SELECT    4   AS Mes
                UNION SELECT    5   AS Mes
                UNION SELECT    6   AS Mes
                UNION SELECT    7   AS Mes
                UNION SELECT    8   AS Mes
                UNION SELECT    9   AS Mes
                UNION SELECT    10  AS Mes
                UNION SELECT    11  AS Mes
                UNION SELECT    12  AS Mes
            ) AS M
INNER JOIN  article         A   ON  MONTH(articleA.content_path) = M.Mes
INNER JOIN  time_accounting TA  ON  TA.article_id               = A.id
INNER JOIN  users           U   ON  U.id                        = A.create_by
INNER JOIN  customer_user   CU  ON  CU.first_name               = U.first_name
                                AND CU.customer_id              = empresa
WHERE       EXTRACT(YEAR FROM A.content_path)   IN (2018)
        and U.last_name                         LIKE CONCAT(customer_userCU.last_name, '%')
        and U.valid_id                          = 1 
        and CU.email                            IN (emails)
GROUP BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
ORDER BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
SELECT      YEAR(A.content_path)                                                    AS anoAtual
        ,   MONTHNAME(M.Mes)                                                        AS Mes
        ,   TIME_FORMAT(SEC_TO_TIME(SUM(IFNULL(TA.time_unit, 0)) * 60), "%H:%i")    AS tempo_total
        ,   CONCAT(U.first_name, ' ', CU.last_name)                                 AS usuario
        ,   CU.email
FROM        (
                SELECT          1   AS Mes
                UNION SELECT    2   AS Mes
                UNION SELECT    3   AS Mes
                UNION SELECT    4   AS Mes
                UNION SELECT    5   AS Mes
                UNION SELECT    6   AS Mes
                UNION SELECT    7   AS Mes
                UNION SELECT    8   AS Mes
                UNION SELECT    9   AS Mes
                UNION SELECT    10  AS Mes
                UNION SELECT    11  AS Mes
                UNION SELECT    12  AS Mes
            ) AS M
INNER JOIN  article         A   ON  MONTH(article.content_path) = M.Mes
INNER JOIN  time_accounting TA  ON  TA.article_id               = A.id
INNER JOIN  users           U   ON  U.id                        = A.create_by
INNER JOIN  customer_user   CU  ON  CU.first_name               = U.first_name
                                AND CU.customer_id              = empresa
WHERE       EXTRACT(YEAR FROM A.content_path)   IN (2018)
        and U.last_name                         LIKE CONCAT(customer_user.last_name, '%')
        and U.valid_id                          = 1 
        and CU.email                            IN (emails)
GROUP BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
ORDER BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
SELECT      YEAR(A.content_path)                                                    AS anoAtual
        ,   MONTHNAME(M.Mes)                                                        AS Mes
        ,   TIME_FORMAT(SEC_TO_TIME(SUM(IFNULL(TA.time_unit, 0)) * 60), "%H:%i")    AS tempo_total
        ,   CONCAT(U.first_name, ' ', CU.last_name)                                 AS usuario
        ,   CU.email
FROM        (
                SELECT          1   AS Mes
                UNION SELECT    2   AS Mes
                UNION SELECT    3   AS Mes
                UNION SELECT    4   AS Mes
                UNION SELECT    5   AS Mes
                UNION SELECT    6   AS Mes
                UNION SELECT    7   AS Mes
                UNION SELECT    8   AS Mes
                UNION SELECT    9   AS Mes
                UNION SELECT    10  AS Mes
                UNION SELECT    11  AS Mes
                UNION SELECT    12  AS Mes
            ) AS M
INNER JOIN  article         A   ON  MONTH(A.content_path) = M.Mes
INNER JOIN  time_accounting TA  ON  TA.article_id               = A.id
INNER JOIN  users           U   ON  U.id                        = A.create_by
INNER JOIN  customer_user   CU  ON  CU.first_name               = U.first_name
                                AND CU.customer_id              = empresa
WHERE       EXTRACT(YEAR FROM A.content_path)   IN (2018)
        and U.last_name                         LIKE CONCAT(CU.last_name, '%')
        and U.valid_id                          = 1 
        and CU.email                            IN (emails)
GROUP BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
ORDER BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
Fonte Link
João Martins
  • 5,7mil
  • 5
  • 16
  • 33

Experimente desta forma:

SELECT      YEAR(A.content_path)                                                    AS anoAtual
        ,   MONTHNAME(M.Mes)                                                        AS Mes
        ,   TIME_FORMAT(SEC_TO_TIME(SUM(IFNULL(TA.time_unit, 0)) * 60), "%H:%i")    AS tempo_total
        ,   CONCAT(U.first_name, ' ', CU.last_name)                                 AS usuario
        ,   CU.email
FROM        (
                SELECT          1   AS Mes
                UNION SELECT    2   AS Mes
                UNION SELECT    3   AS Mes
                UNION SELECT    4   AS Mes
                UNION SELECT    5   AS Mes
                UNION SELECT    6   AS Mes
                UNION SELECT    7   AS Mes
                UNION SELECT    8   AS Mes
                UNION SELECT    9   AS Mes
                UNION SELECT    10  AS Mes
                UNION SELECT    11  AS Mes
                UNION SELECT    12  AS Mes
            ) AS M
INNER JOIN  article         A   ON  MONTH(article.content_path) = M.Mes
INNER JOIN  time_accounting TA  ON  TA.article_id               = A.id
INNER JOIN  users           U   ON  U.id                        = A.create_by
INNER JOIN  customer_user   CU  ON  CU.first_name               = U.first_name
                                AND CU.customer_id              = empresa
WHERE       EXTRACT(YEAR FROM A.content_path)   IN (2018)
        and U.last_name                         LIKE CONCAT(customer_user.last_name, '%')
        and U.valid_id                          = 1 
        and CU.email                            IN (emails)
GROUP BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes
ORDER BY    A.create_by
        ,   YEAR(A.content_path)
        ,   M.Mes

A ideia é fazer um JOIN com uma tabela já com todos os meses e depois apresentar a informação de cada um.

Foi colocado o `IFNULL` para caso um dos meses não tenha informação apresentar o valor "0" na coluna `tempo_total`.