如何检查每条路线的完整出行次数

时间:2017-01-11 10:57:27

标签: sql sql-server

我的桌子每条路线有多个点。我想检索每条路线发生的完整旅行次数。标记1 - > 5次一趟。

任何建议都将不胜感激。

enter image description here

2 个答案:

答案 0 :(得分:0)

如果旅程始终从标记1和步骤标记开始,但它可以在到达最终标记之前停止,您可以使用:

if let getText = self.getStartedDict["Value"]?.htmlStringToAttributedString(){
        let aText = getText
        let myRange = NSRange(location: 0, length: aText.length)
        aText.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(kFontSize), range: myRange)
        cell.detail.attributedText = aText
        cell.detail.setLinksForSubstrings(["Health Action Plan"], withLinkHandler: handler)
    }
    else{
        print("No text found")
    }

如果旅行“触及”的标记完全是随机的,但您需要计算您拥有的标记数量,请使用此标记:

select routeid, count(marker) trip_n
from RouteTable 
where marker=5
group by routeid

答案 1 :(得分:0)

select distinct m1.routeid, isnull(m2.[Trips],0)
from [TableName] m1
left join
(SELECT routeid, count(*) / 5 as [Trips]
  FROM [Tablename] m
  where 5 = (select count(distinct marker) 
  from [TableName]
  where routeid=m.routeid)
  group by routeid) m2
  on m1.routeid=m2.routeid

添加了[标记]表中的动态标记数:

select distinct m1.routeid, isnull(m2.[Trips],0)
from [TableName] m1
left join
(SELECT routeid, count(*) / 5 as [Trips]
  FROM [Tablename] m
  where (select [no_of_markers] from [Markers] where [route_id]=m.route_id) = (select count(distinct marker) 
  from [TableName]
  where routeid=m.routeid)
  group by routeid) m2
  on m1.routeid=m2.routeid