|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
having 的用法是对聚合函数进行限定,一般用where 对表中字段条件进行限制就可以了,where的速度要快
union 比union all 慢很多,要对所有结果进行排序,有重复记录就保留唯一的记录,这里很明显没有重复记录,请用union all
union 或union all 后面的字段名没有意义,所以我们可以不定义,唯有union 前面的查询字段有意义。
SELECT Sheet1.车队, '' AS 拖车号, "" AS 客户名称, Sum(Sheet1.应收) AS 应收, Sum(Sheet1.应付) AS 应付, 应收-应付 AS 收入
FROM Sheet1
where Sheet1.车队="aaa"
GROUP BY Sheet1.车队
UNION all
select "合计","","",sum(sheet1.应收),sum(sheet1.应付),(sum(sheet1.应收)-sum(sheet1.应付))
FROM Sheet1
where Sheet1.车队="aaa" |
|