我有这样的查询:
SELECT v.Vtype,
SUM(DATEDIFF(MI, t.Paydate, t.DelDate)) AS TotalDiff,
CONVERT(DECIMAL(10, 1),
AVG(CONVERT(NUMERIC(18, 2), DATEDIFF(MI, t.Paydate, t.DelDate)))) AS Average
FROM Transaction_tbl t
LEFT JOIN VType_tbl v
ON t.vtid = v.vtid
WHERE t.Locid = 5
GROUP BY v.Vtype
平均来自 Transaction_tbl t left join VType_tbl v on t.vtid=v.vtid where t.Locid =5 group by v.Vtype
我的输出:
Vtype TotalDiff 平均 -------------------------------------------------- - Emaar 员工 NULL NULL 正常 14044 189.8 贵宾 85 2.1 贵宾 5 2.5
但我想像这样出去:
VtypeE Etotaldiff 平均 VtypeN Ntot Naverge vtypev vtot vaverg Emaar 法杖 null null 普通 14044 189.8 VIP 85 2.1