C# 根据ID返回字段和的SQL查询

C# 根据ID返回字段和的SQL查询,c#,asp.net,sql-server-2008,gridview,C#,Asp.net,Sql Server 2008,Gridview,上图是SQL表中的内容 我有一个查询,它在底部的gridview中给出了结果。查询将在TransTypeDesc列中返回最大的估计传输时间。正如你所看到的,汽车是第一季度最大的一辆 我唯一没有的是基于DisplayNum的总估计传输时间。对于Q1,我应该有31分钟 SELECT t1.DisplayNum, t1.TransTypeDesc, t1.SubQueueId, t1.EstimatedTransTime FROM vwQueueData AS t1 LEFT OUTE

上图是SQL表中的内容

我有一个查询,它在底部的gridview中给出了结果。查询将在TransTypeDesc列中返回最大的估计传输时间。正如你所看到的,汽车是第一季度最大的一辆

我唯一没有的是基于DisplayNum的总估计传输时间。对于Q1,我应该有31分钟

  SELECT t1.DisplayNum, t1.TransTypeDesc, t1.SubQueueId, t1.EstimatedTransTime 
  FROM vwQueueData AS t1 
  LEFT OUTER JOIN vwQueueData AS t2 ON t1.DisplayNum = t2.DisplayNum AND t1.EstimatedTransTime < t2.EstimatedTransTime 
  WHERE (t2.DisplayNum IS NULL) AND (t1.Called IS NULL) AND (t1.SubQ = @SubQ) 
选择t1.DisplayNum、t1.TransTypeDesc、t1.SubQueueId、t1.EstimatedTransTime
从vwQueueData中选择t1
左侧外部连接队列数据为t1.DisplayNum=t2.DisplayNum和t1.EstimatedTransTime


下面是SQL提示:

您需要按照以下步骤执行操作:

SELECT t1.DisplayNum, t1.TransTypeDesc, t1.SubQueueId, SUM(t1.EstimatedTransTime) 
FROM vwQueueData AS t1 
LEFT OUTER JOIN vwQueueData AS t2 
     ON t1.DisplayNum = t2.DisplayNum AND 
        t1.EstimatedTransTime < t2.EstimatedTransTime 
WHERE (t2.DisplayNum IS NULL) AND 
      (t1.Called IS NULL) AND (t1.SubQ = @SubQ)
GROUP BY t1.DisplayNum, t1.TransTypeDesc, t1.SubQueueId
选择t1.DisplayNum、t1.TransTypeDesc、t1.SubQueueId、SUM(t1.EstimatedTransTime)
从vwQueueData中选择t1
左外联接数据为t2
在t1.DisplayNum=t2.DisplayNum和
t1.EstimatedTransTime
基本上,将SUM函数添加到“EstimatedTransTime”列中。
然后在DisplayNum列上执行分组,以获得所需的输出。

您需要按照以下步骤执行操作:

SELECT t1.DisplayNum, t1.TransTypeDesc, t1.SubQueueId, SUM(t1.EstimatedTransTime) 
FROM vwQueueData AS t1 
LEFT OUTER JOIN vwQueueData AS t2 
     ON t1.DisplayNum = t2.DisplayNum AND 
        t1.EstimatedTransTime < t2.EstimatedTransTime 
WHERE (t2.DisplayNum IS NULL) AND 
      (t1.Called IS NULL) AND (t1.SubQ = @SubQ)
GROUP BY t1.DisplayNum, t1.TransTypeDesc, t1.SubQueueId
选择t1.DisplayNum、t1.TransTypeDesc、t1.SubQueueId、SUM(t1.EstimatedTransTime)
从vwQueueData中选择t1
左外联接数据为t2
在t1.DisplayNum=t2.DisplayNum和
t1.EstimatedTransTime
基本上,将SUM函数添加到“EstimatedTransTime”列中。
然后在DisplayNum列上执行分组,以获得所需的输出。

您希望如何在多种可能性中选择
TransTypeDesc
?@dasblinkenlight TransTypeDesc将是最高的EstimatedTransTime@dasblinkenlightTrasTypeDesc已经开始工作了,我只需要对Q1的所有估计传输时间求和示例。由于EstimatedTransTime列的类型为
varchar
,因此很难求和()。您需要确保它是一个实际的数字列或总和不会按您想要的方式工作。@Evan Lewis它是一个int。忽略Min您希望如何在几种可能性中选择
TransTypeDesc
?@dasblinkenlight TransTypeDesc将是最高的EstimatedTransTime@dasblinkenlightTrasTypeDesc已经开始工作了我只需要例如,对Q1的所有EstimatedTransTime进行求和。由于EstimatedTransTime列的类型为
varchar
,因此很难求和()。您需要确保它是一个实际的数字列或总和不会按您想要的方式工作。@Evan Lewis它是一个int。忽略Mints这个stills不会添加,但我认为我们正在朝着正确的方向前进。请尝试下面的方法。我使用了你的链接。缺少一些列和联接,使示例更简单。基本上,下面的查询为您提供了所需的内容:通过t1.DisplayNum从tblTest中选择t1.DisplayNum,SUM(t1.EstimatedTransTime)作为t1 GROUP BY t1.DisplayNum,该查询不显示最大的TransTypeDesc。我需要有总和和最大值,这仍然没有增加,但我可以认为我们正在朝着正确的方向前进。试试下面的。我使用了你的链接。缺少一些列和联接,使示例更简单。基本上,下面的查询为您提供了所需的内容:通过t1.DisplayNum从tblTest中选择t1.DisplayNum,SUM(t1.EstimatedTransTime)作为t1 GROUP BY t1.DisplayNum,该查询不显示最大的TransTypeDesc。我需要求和和和最大的TransTypeDesc