我有两个 sql 查询...
set @count:=0;
select @count:=@count+1 as SNO, col1, col2 FROM table;
我想将上述查询组合成一个查询。有什么帮助吗?
你可以简单地做到这一点,
select @count:=@count+1 as SNO, col1, col2
FROM table, (SELECT @count:=0) r ;
就像为每一行添加 RowNumber
select @rownum:=@rownum+1 ‘rank’,
p.*
from player p, (SELECT @rownum:=0) r
order by score
desc limit 10;
据我了解,在这种情况下,您正在寻找 Row_Number 函数。如果这是正确的,请看这里
例如
Select @count := @count + 1 As SNO, col1, col2
From table ,(SELECT @count:=0) foo
可能有帮助
您也可以参考MySQL 中的 ROW_NUMBER、Partition 和 Over 以获得更多理解
结合两个查询..
SELECT t1.field1, t1.field2, t2.field1
FROM (query1) as t1, (query2) as t2
WHERE t1.field1= t2.field1
希望这会奏效......
select @count:=@count+1 as SNO, col1, col2 FROM table, (SELECT @count:=0) t;