首页 > 其他分享 >3.18

3.18

时间:2024-06-18 20:25:07浏览次数:24  
标签:3.18 name transfer stop next station SELECT

今天我们在网上找到了相关的视频讲解,是利用SQL语句的递归查询,听了视频的相关讲解,也算是理解了吧。

以一号线的王府井到二号线的积水潭为例

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 WITH RECURSIVE transfer (start_station, stop_station, stops, path) AS (   SELECT station_name, next_station, 1, CAST(CONCAT(line_name,station_name , '->', line_name,next_station) AS CHAR(1000))     FROM bj_subway WHERE station_name = '王府井'    UNION ALL   SELECT p.start_station, e.next_station, stops + 1, CONCAT(p.path, '->', e.line_name, e.next_station)     FROM transfer p     JOIN bj_subway e       ON p.stop_station = e.station_name AND (INSTR(p.path, e.next_station) = 0) ) SELECT * FROM transfer WHERE stop_station ='积水潭';   -- Oracle WITH transfer (start_station, stop_station, stops, path) AS (   SELECT station_name, next_station, 1, line_name||station_name||'->'||line_name||next_station     FROM bj_subway WHERE station_name = '王府井'    UNION ALL   SELECT p.start_station, e.next_station, stops + 1, p.path||'->'||e.line_name||e.next_station     FROM transfer p     JOIN bj_subway e       ON p.stop_station = e.station_name AND (INSTR(p.path, e.next_station) = 0) ) SELECT * FROM transfer WHERE stop_station ='积水潭';   -- SQL Server WITH transfer(start_station, stop_station, stops, paths) AS ( SELECT station_name, next_station, 1 stops,        CAST(concat(line_name,station_name,'->',line_name,next_station) AS varchar(1000)) AS paths FROM bj_subway WHERE station_name = '王府井' UNION ALL SELECT t.start_station, s.next_station, stops+1, CAST(concat(paths, '->', s.line_name, s.next_station)  AS varchar(1000)) FROM transfer t JOIN bj_subway s ON (t.stop_station = s.station_name AND charindex(s.next_station, paths)=0) ) SELECT * FROM transfer WHERE stop_station = '积水潭';   -- PostgreSQL WITH RECURSIVE transfer (start_station, stop_station, stops, path) AS (   SELECT station_name, next_station, 1, ARRAY[station_name::text, next_station::text]     FROM bj_subway WHERE station_name = '王府井'    UNION ALL   SELECT p.start_station, e.next_station, stops + 1, p.path || ARRAY[e.next_station::text]     FROM transfer p     JOIN bj_subway e       ON p.stop_station = e.station_name AND NOT e.next_station = ANY(p.path) ) SELECT * FROM transfer WHERE stop_station ='积水潭';   -- SQLite WITH RECURSIVE transfer(start_station, stop_station, stops, paths) AS ( SELECT station_name, next_station, 1 stops,        line_name||station_name||'->'||line_name||next_station AS paths FROM bj_subway WHERE station_name = '王府井' UNION ALL SELECT t.start_station, s.next_station, stops+1, paths||'->'||s.line_name||s.next_station FROM transfer t JOIN bj_subway s ON (t.stop_station = s.station_name AND instr(paths, s.next_station)=0) ) SELECT * FROM transfer WHERE stop_station = '积水潭'; Footer

标签:3.18,name,transfer,stop,next,station,SELECT
From: https://www.cnblogs.com/binglinll/p/18255028

相关文章

  • 3.18
    由数据范围反推算法复杂度以及算法内容一般ACM时间限制是1-2秒这种情况下,c++代码操作次数控制在1e7~1e8下面给出在不同数据范围下,代码时间复杂度和算法如何选择1.n<=30,指数级别,dfs+剪枝,状态压缩dp2.n<=100=>O(n3),floyd,dp,高斯消元3.n<=1000=>O(n2),O(n2logn),dp,二分,朴......
  • 周报 | 24.3.18-24.3.24文章汇总
    为了更好地整理文章和发表接下来的文章,以后每周都汇总一份周报。数据分析及应用|超强!深度学习Top10算法!(建议收藏!)-CSDN博客OpenCV与AI深度学习|使用PyTorch进行小样本学习的图像分类-CSDN博客周报|24.3.11-24.3.17文章汇总-CSDN博客Datawhale|等来了Open-Sora全面......
  • 上周热点回顾(3.18-3.24)
    热点随笔:· 京东大佬问我:下单后30分钟未支付,自动取消有什么设计方案么? (帝莘)· 园子的新版favicon,您觉得哪款更好看 (博客园团队)· Garnet:力压Redis的C#高性能分布式存储数据库 (InCerry)· 没想到三天10KStar的营销利器MediaCrawler开源作者已经删库了 (aehyok)·......
  • 2024.3.18软件工程日报
    学习时间1h代码量100packagecom.example.text_five;importandroid.content.Intent;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.EditText;importandroid.widget.TimePicker;importandroid.widget.Toast;importandroidx.appcompat.app.AppCo......
  • SMU Winter 2024 div2 ptlks的周报Week 6(3.18-3.24)
    不难想到,要求环的期望,只需求出所有可能的环的长度总和和不相邻点对的组数。而边数确定,则只需求环的总长。对于两个不相邻的点x,y,所形成的环的长度等于两点深度之差加一,\(\vertdp[x]-dp[y]\vert+1\),不妨令x为根节点,则只需求所有节点的深度之和,再减去相邻的点,最后对树进行换根dp,输出......
  • #17 2023.3.18
    645.loj4038「SNOI2024」树V图646.loj4039「SNOI2024」矩阵647.loj4040「SNOI2024」拉丁方648.loj4041「SNOI2024」平方数649.loj4042「SNOI2024」公交线路650.loj3903「PA2022」Palindrom651.loj3904「PA2022」WielkiZderzaczTermionów652.loj......
  • 2024.3.18-隐私计算-隐语-数据可信流通,从运维信任到技术信任
    学习感受本节课从背景介绍、可信/非可信与数据流通之间的关系、提出关于技术实现数据流通安全的解决方案笔记1:可信与非可信之间的关系可信:身份可确认、利益可依赖、能力有预期、行为有后果关于可信的定义/规则,其实在外循环当中其实很难去遵守,因为身份追踪是比......
  • 复习java的第一天3.18的文章
    大家好,我准备在这里记录我每天的学习(复习)java的成果,以及计划和规划,为的就是希望能找几个月后能找一份工作,并且我希望自己能坚持下去,养成一个良好的习惯,让自己不再那么迷茫,与其内耗不如做点有意义有方向的事情.之前我一直想不明白自己到底想要干什么,因为网上看着大家都说......
  • 英语随笔,发散了 3.18
    todayihavesomethingsthatwanttosharewithu.iwatchedavideobefore,andtodayiwatcheditagain.ifoundsomethingmeaningfulfromthepeople'stalking.shesaid:"thereisnostagethatucanjustgetthrough."wealwayshopetoget......
  • 3.18
    1.建立空项目2.在project下创建libs导入mysql-connector-java.jar(导入5.+的) 3.在manifests添加<uses-permissionandroid:name="android.permission.INTERNET"/> 4.配模拟器5.开远程访问权限6. 7.编写主界面 5.运行即可出现helloworld......