在Sql Select上使用变量

时间:2018-04-19 12:54:52

标签: mysql

我有这个问题:

SELECT * 
FROM (
    SELECT @z := ticketing_ticket.id_ticket_category as id, ticketing_ticket.email,
    CONCAT(
          TIMESTAMPDIFF(day,date_create,date_close) , ' jours '
    ) AS 'temps de traitement '
    FROM ticketing_ticket 
    WHERE DATE(date_close) = CURDATE()
) AS X
CROSS JOIN (
    SELECT GROUP_CONCAT(T2.label SEPARATOR ';') AS 'Domaines', @z as id
    FROM (
        SELECT @r AS _id,
             (SELECT @r := id_parent 
              FROM ticketing_category 
              WHERE id_category = _id) AS parent_id,
              @l := @l + 1 AS lvl
        FROM ( SELECT @r :=@z , @l := 0) vars
        CROSS JOIN ticketing_category m
        WHERE @r <> 0
    ) T1
    JOIN ticketing_category T2
        ON T1._id = T2.id_category
) AS Y;

输出:

+----+------------------+----------+-----------------------------+----+
| ID |       EMAIL      | DURATION |           DOMAINS           | ID |
+----+------------------+----------+-----------------------------+----+
| 35 |  p.p@yopmail.com | 65 jours | Elec_Domain;Help_Sub_Domain | 38 |
+----+------------------+----------+-----------------------------+----+
| 36 | test@yopmail.com | 63 jours | Elec_Domain;Help_Sub_Domain | 38 |
+----+------------------+----------+-----------------------------+----+
| 28 |  admin@admin.com | 29 jours | Elec_Domain;Help_Sub_Domain | 38 |
+----+------------------+----------+-----------------------------+----+
| 38 |   test@test.com  | 21 jours | Elec_Domain;Help_Sub_Domain | 38 |
+----+------------------+----------+-----------------------------+----+
| 38 |   test@test.com  | 21 jours | Elec_Domain;Help_Sub_Domain | 38 |
+----+------------------+----------+-----------------------------+----+

我的问题是我希望在我的第二个id上使用sub-select,但输出结果与id相同。 我的要求出了什么问题?

0 个答案:

没有答案