我有以下记录集。
lgh_driver1 | lgh_number | Origin Company ID | First Pickup Company ID | Second Pickup Company ID | First Drop Company ID | Second Drop Company ID | Ending Company ID | Event Time
XXXXXX 111111 XXXXWAR 15
XXXXXX 111111 GORMC 199
XXXXXX 111111 ERGCON 944
XXXXXX 111111 QUASAL 45
XXXXXX 111111 QUASAL 45
XXXXXX 111111 XXXXWAR 15
理想情况下,我想要做的是将这些组合起来,以便我获得1 lgh驱动程序1 lgh数字,并且所有公司在一行中列出事件时间总和。我希望有一个相对简单的解决方案,我忽略了,但任何解决方案都会在这一点上做。任何想法或意见将不胜感激。谢谢。
答案 0 :(得分:1)
如果每个lgh_number只有一个公司记录,则可以像这样使用SQL:
SELECT Table1.lgh_driver1, Table1.lgh_number, Max(Table1.[Origin Company ID]) AS [MaxOfOrigin Company ID], Max(Table1.[First Pickup Company ID]) AS [MaxOfFirst Pickup Company ID], Max(Table1.[Second Pickup Company ID]) AS [MaxOfSecond Pickup Company ID], Max(Table1.[First Drop Company ID]) AS [MaxOfFirst Drop Company ID], Max(Table1.[Second Drop Company ID]) AS [MaxOfSecond Drop Company ID]
FROM Table1
GROUP BY Table1.lgh_driver1, Table1.lgh_number;
最大聚合函数将为每个公司列返回非空值