使用count来确定出现并连接数据

时间:2017-06-14 12:11:52

标签: sql sql-server tsql

我试图找出CR.DestinationDepot是否有两个记录,然后将它们连接起来(例如):KNI / KHN,而不是它现在如何连接。有任何想法吗?谢谢。

enter image description here

 select CR.DestinationCountry,
 mm.MovementRef,
CR.DestinationDepot,
case when count(CR.DestinationDepot) >= 2 then 'yes' else 'no' end as [statement],
 Case when (CR.DestinationCountry <> 'GB') and count(CR.DestinationDepot) >= 2 then CR.DestinationDepot+'/'+CR.DestinationDepot else CR.DestinationDepot end as [DestinationDepot]
 FROM    dbo.MALExport AS ME
    INNER JOIN dbo.movConLink AS MCL ON ME.ConsignmentReference = MCL.ConsignmentReference
    INNER JOIN dbo.cgtRoute AS CR ON CR.RouteID = MCL.CMRRouteID
    INNER JOIN dbo.movMovement AS MM ON MM.MovementRef = ME.MovementReference
    group by cr.DestinationCountry, cr.DestinationDepot, mm.MovementRef

1 个答案:

答案 0 :(得分:0)

以下代码应该是您正在寻找的代码

<div style="word-break: break-all;">
        {{vm}}
    </div>