QD ZD SJ
-------- -------------------- --------------------
田林 桂林 8:00
田林 桂林 9:00
桂林 田林 8:00
桂林 田林 8:00
田林 宜山 8:00
宜山 田林 8:00
6 rows selected
统计这个表里面 的线路条数
起点和终点 一致的算一条
现在结果是两条
------解决方案--------------------
select count(*) from 表名 group by QD,ZD
------解决方案--------------------
select count(*) from (select qd,zd from tb group by qd,zd having count(*) > 1) t
------解决方案--------------------
select count(distinct(case when QD > ZD then QD||ZD else ZD||QD end) )
from table
------解决方案--------------------
已經建表測試過的SQL:
- SQL code
select count(*)/2 from (select distinct QD,ZD from tbl_luxianunion select distinct ZD,QD from tbl_luxian) a
------解决方案--------------------
------解决方案--------------------
经测试可行:
select count(*) from (select rank() over(partition by QD,ZD
order by id) rank from 表名) n where n.rank = '2'
order by 后面 跟其他不会重复的字段。这样就是起点和终点一致的数据有n条也算作1条