duanjiu6697 2016-08-05 11:25
浏览 189
已采纳

Mysql递归查询无法在MariaDB上运行

I have a table "knowledgemodel" [enter image description here][1]

My Query

SELECT 
  title, id, @parent:=parent_id as prnt
FROM
(SELECT @parent:=3 ) a
JOIN
(SELECT * FROM knowledgemodel ORDER BY id DESC) b
where 
@WHERE=id

enter image description here

IN MYsql Server: 127.0.0.1 via TCP/IP Server type: MySQL Server version: 5.6.16 - MySQL Community Server (GPL) Protocol version: 10 Above Query was working fine.

But on MariaDB im getting only one record enter image description here

Any help ??

  • 写回答

1条回答

  • douyan4470 2016-08-08 05:54
    关注

    I found the problem and fix the issue.

    SELECT T2.id, T2.title,T2.parent_id as prnt

    FROM (

    SELECT @r AS _id,

    (SELECT @r := parent_id FROM knowledgemodel WHERE id = _id) AS parent_id,

    @l := @l + 1 AS lvl

    FROM (

    SELECT @r := ".$value['path'].", @l := 0) vars, knowledgemodel m WHERE @r <> 0)

    T1 JOIN knowledgemodel T2 ON T1._id = T2.id ORDER BY T1.id asc

    The LNine SELECT "$value['path']" @r := 5 is the ID . The result is as follows:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?