mysql数据库遍历表,其一字段获取上一条数据
注意:
- 如果非主鍵索引會非常慢,等于兩個for循環遍歷,比如10000條數據主鍵關聯就是10000次,非主鍵就是10000*10000變的非常慢。
方法一:SQL語句
SELECT a.joint_id,a.seq_num,a.sws_orientation,a.swe_orientation,a.start_wc,b.joint_id,b.seq_num,b.sws_orientation,b.swe_orientation,b.start_wc FROM JOINT a?
JOIN JOINT b ON a.joint_id =b.joint_id+1
方法二:創建視圖
DROP VIEW IF EXISTS `look_up_query`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `look_up_query` AS select `event_type`.`description` AS `event_type`,`pof_look_up`.`type_abbr` AS `type_abbr`,`pof_feature_catalog`.`abbr` AS `pof_type_abbr`,`pof_feature_id_catalog`.`abbr` AS `pof_id_abbr`,`pof_metal_loss_catalog`.`abbr` AS `pof_class` from (`pof_metal_loss_catalog` join (`event_type` join (`pof_feature_id_catalog` join (`pof_feature_catalog` join `pof_look_up` on((`pof_feature_catalog`.`type` = `pof_look_up`.`pof_type`))) on((`pof_feature_id_catalog`.`type` = `pof_look_up`.`pof_id`))) on((`event_type`.`type` = `pof_look_up`.`event_type`))) on((`pof_metal_loss_catalog`.`type` = `pof_look_up`.`pof_class`))) order by `event_type`.`type`,`pof_look_up`.`type` ;
?
總結
以上是生活随笔為你收集整理的mysql数据库遍历表,其一字段获取上一条数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell 命令自动识别系统升级内核、系
- 下一篇: Linux下编译运行Go程序