QD ZD SJ
-------- -------------------- --------------------
田林 桂林 8:00
田林 桂林 9:00
桂林 田林 8:00
桂林 田林 8:00
田林 宜山 8:00
宜山 田林 8:006 rows selected
统计这个表里面 的线路条数
起点和终点 一致的算一条
现在结果是两条
-------- -------------------- --------------------
田林 桂林 8:00
田林 桂林 9:00
桂林 田林 8:00
桂林 田林 8:00
田林 宜山 8:00
宜山 田林 8:006 rows selected
统计这个表里面 的线路条数
起点和终点 一致的算一条
现在结果是两条
from table
select distinct QD,ZD from tbl_luxian
union
select distinct ZD,QD from tbl_luxian
) a
功能雖實現,效率可能不太好~ 期待高手
select
(select count(*) from (select distinct QD,ZD from lsb_tmp) )-
(select count(*)/2 from (select distinct QD,ZD from lsb_tmp) a ,(select distinct QD,ZD from lsb_tmp) b where a.QD=b.ZD and b.QD=a.ZD ) as result from dual ;
select count(*) from (select rank() over(partition by QD,ZD
order by id) rank from 表名) n where n.rank = '2'order by 后面 跟其他不会重复的字段。这样就是起点和终点一致的数据有n条也算作1条
第一种:select count(distinct(case
when QD > ZD then
QD || ZD
else
ZD || QD
end)) as 总线路
from route;第二种:
select count(*)
from (SELECT a.qd, a.zd
FROM route a
JOIN route b ON a.qd = b.zd
AND a.zd = b.qd
WHERE a.qd < b.qd
GROUP BY a.qd, a.zd
);第三种:
select count(*) / 2
from (select distinct QD, ZD
from route
union
select distinct ZD, QD from route) a;第三种:
select count(*) / 2
from (select distinct QD, ZD
from route
union
select distinct ZD, QD from route) a;第四种:
select (select count(*) from (select distinct QD, ZD from route)) -
(select count(*) / 2
from (select distinct QD, ZD from route) a,
(select distinct QD, ZD from route) b
where a.QD = b.ZD
and b.QD = a.ZD) as result
from dual;其中第二种,出现单程统计不到了。