且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据特定列的数据自动递增

更新时间:2023-10-05 09:18:52

对于oracle,我们有 ROW_NUMBER()OVER PARTITION BY 语句,但是对于Mysql来说,实现此语句仍然很棘手.最有可能的是,我们将使用此实现来限制数据在组之间的降序/升序.

When it comes to oracle we have ROW_NUMBER() OVER PARTITION BY statement but for Mysql it is still tricky to implement this one. As most probably we will use this implementation to limit data either descending/ascending order across groups.

在这里,您可以使用类似的实现方式作为参考:

Here you go with the similar implementation for your reference:

SELECT @row_number:=CASE WHEN @category=category 
THEN @row_number+1 ELSE 1 END AS feeds,@category:=category AS category, content
FROM table1, (SELECT @row_number:=0,@category:='') AS t
ORDER BY category;

SQLFiddle链接