【发布时间】:2017-02-14 17:06:59
【问题描述】:
我试图在这个 sql 语法的底部添加一个 Total 行,但到目前为止还没有收到突破。我查看了以下内容,但他们都不符合我的条件。有人可以提供这方面的帮助吗?
Adding a total row to the end of query result
select dm.Builder ||' ('|| dm.Lot_Size || '''s)' as"Builder",count(sd.Address) "The Count",
dm."Construction_ID"
from input dm
left join data sd on sd.inputfk = dm.inputpk
and sd.Closing Date >= DATE '01/01/2017' and sd.Closing Date < DATE '06/30/2017'
where dm.Construction_ID = 'AJR'
group by dm.Builder,dm.Lot_Size, dm.Project_ID
having count(sd.Address) > 0
order by dm.Builder
当我运行它时:
Builder The Count Construction_ID
Jake's Homes (55's) 2 AJR
Jake's Homes (65's) 3 AJR
Maggie's Homes (65's) 5 AJR
Maggie's Homes (66's) 2 AJR
Maggie's Homes (75's) 3 AJR
Maggie's Homes (90's) 1 AJR
Total ----------> 16
【问题讨论】:
-
I am oblivious on why the result shows ones redundantly for the same Builders and Lot Size combinations even though I have grouped by ALL the columns in the script.-- 可能是因为sd.Address? -
是的,需要删除
sd.Address。
标签: sql postgresql