嗨,我正在尝试在 mysql 视图中实现行自动编号。我确实从用于在结果集中自动编号行的纯 SQL 技术开始并让它工作。然后我尝试调整它并得到了几乎那里....现在我被stuMainmped
该视图列出了狗 (CaneID) 及其后代 (AvoID)。我想要实现的是每次主狗(CaneID)发生变化时重新开始编号,这样我就可以让每个上升者都属于从 1 开始的狗号。
到目前为止,它只对第一只狗起作用,以下仍然按顺序编号,但不是从 1 开始。
这是我的视图查询:
SELECT
`avi1`.`CaneID`,
`avi1`.`Cane`,
`avi1`.`PedPos`,
`avi1`.`AvoID`,
`avi1`.`Avo`,
`avi1`.`Ripetuto`,
(
SELECT
count(0)
FROM
`v_avi_ripetuti` `Avi2`
WHERE
(
(`avi2`.`Ripetuto` > 1)
AND (`avi2`.`CaneID` <= `avi1`.`CaneID`)
AND (`avi2`.`AvoID` <= `avi1`.`AvoID`)
)
ORDER BY
`avi2`.`CaneID`,
`avi2`.`AvoID`
) AS `RowNumber`
FROM
`v_avi_ripetuti` `Avi1`
WHERE
(`avi1`.`Ripetuto` > 1)
ORDER BY
`avi1`.`CaneID`,
`avi1`.`AvoID`
我现在得到的是:
CaneID Cane AvoID Avo RowNumber
---------------------------------------------------------------------
2 Antigua 472 Anika v. Stammhaus Eike 1
2 Antigua 527 Britta v.d. Römerlinde 2
2 Antigua 642 Ares v. Nettenberg 3
2 Antigua 657 Carmen v. Westfalenzwinger 4
2 Antigua 658 Leu v. Stammhaus Eike 5
2 Antigua 684 Chipsy v. Theresienhof 6
2 Antigua 1662 Astrit v.d. Burrlinde 7
-----------------------> New Main dog<-------------------------------
3 Ambra Gaya 472 Anika v. Stammhaus Eike 2
3 Ambra Gaya 657 Carmen v. Westfalenzwinger 6
3 Ambra Gaya 658 Leu v. Stammhaus Eike 8
3 Ambra Gaya 684 Chipsy v. Theresienhof 10
3 Ambra Gaya 718 Leo v. guten Löwen 11
3 Ambra Gaya 1022 Zara v. Ratibor u. Corvey 12
3 Ambra Gaya 1024 Ruth v. Ratibor u. Corvey 13
3 Ambra Gaya 1050 Dunja v. Hofoldinger Forst 14
3 Ambra Gaya 1200 Icksle v. Ratibor u. Corvey 15
3 Ambra Gaya 1227 Troldegaards Tanja 16
3 Ambra Gaya 1228 Anemone v. Ratibor u. Corvey 17
-----------------------> New Main dog<-------------------------------
3371 Always Habit 600 Absinthe v. Kallenberg 4
3371 Always Habit 750 Mathoaka's Relaxing Boy 13
3371 Always Habit 2560 Leijonamielen Luvaton Lyyli 21
我对 mysql 非常陌生(一周前安装)并且非常努力地留下访问权限....请耐心等待。