所以我有一张像
这样的桌子
现在我需要在填充了uv ='owner'的组合框中进行选择时将其打包到datagridview中。 如果我选择uv,例如MG。我得到了他所有文件/ dosno的列表,以及他在文件上工作的时间。
我使用此查询执行此操作:
SELECT kbpres.uv,
dbo.doss.dosno,
SUM(dbo.kbpres.uur) AS somuur,
SUM(dbo.kbpres.minuut) AS somminuut,
CAST (( SUM(dbo.kbpres.uur) + SUM(dbo.kbpres.minuut) / 60 ) AS VARCHAR(4)
) +
'u ' + CAST (( SUM(dbo.kbpres.minuut) % 60 ) AS VARCHAR(2)) + 'm' AS
[derivedColumn],
doss.behdr
FROM dbo.kbpres
INNER JOIN dbo.doss
ON dbo.kbpres.ino = dbo.doss.ino
WHERE ( dbo.kbpres.uv LIKE @cboBeheerder )
GROUP BY kbpres.uv,
dbo.doss.dosno,
doss.behdr
(尽管我只想按照UV分组,并且还要添加dosno和behdr?)
现在的问题是,我如何计算正确的成本,因为它与每条记录的不同。 对于MG,它将是:
10 * 60 for dosno 88888
2066,适用于66666
60 * 10 +(28小时+10分钟* 10)+ 10 * 2表示12345
知道这是否可能?
答案 0 :(得分:0)
SELECT dosno,
SUM(uur)*60 + SUM(minuut) AS Time,
(SUM(uur)*60 + SUM(minuut)) * cost AS TotalCost
FROM dbo.kbpres k
INNER JOIN dbo.doss d ON k.ino = d.ino
GROUP BY dosno,k.ino,d.ino,cost
WHERE k.uv = 2
因为成本似乎是uv和dosno的功能所以尝试
SELECT dosno,SUM(Time) AS Time,SUM(TotalCost) AS TotalCost FROM
(
SELECT dosno,
uur*60 + minuut AS Time,
(uur*60 + minuut) * cost AS TotalCost
FROM dbo.kbpres k
INNER JOIN dbo.doss d ON k.ino = d.ino
GROUP BY dosno,k.ino,d.ino,cost
WHERE k.uv = 2
) t
GROUP BY dosno