这是我的问题:
select * from a
JOIN B
ON
a.id=B.id
JOIN C
ON
B.id=C.id
如何在开头添加一个名为' serial_id'哪个是自动增量?
我见过这里的例子:MySQL query to select results with auto increment as a new column added in the result
但是当我加入select语句时,解决方案不起作用。
答案 0 :(得分:1)
试试这种方式
SELECT *
,@a:= @a +1 `serial_no`
FROM a
JOIN B
ON
a.id=B.id
JOIN C
ON
B.id=C.id
JOIN (SELECT @a:=0) t
或
SELECT *
,@a:= @a +1 `serial_no`
FROM a , (SELECT @a:=0) t
JOIN B
ON
a.id=B.id
JOIN C
ON
B.id=C.id