Aggr
Jul 23, 2005
Hi,
What I want is to to get SUM of col1 and list quarter data when
applicable.
DDL:
create table #temp (col1 int, rent int, transport int, qtr smallint,
other int);
DML:
insert into #temp
values(1, 800, 300, 1, 200)
insert into #temp
values(1, 800, 300, 2, 300)
insert into #temp
values(2, 800, 300, 2, 400)
Data retrieval DML:
select col1, sum(other) as other_Total, case when qtr = 1 then
sum(other) end qtr_total
from #temp
group by col1,qtr
Current Resultset:
col1 other_Total qtr_total
----------- ----------- -----------
1 200 200
1 300 NULL
2 400 NULL
Desirable Resultset: (get ride of the middle row above and add up the
200 and 300), so, it would look like
col1 other_Total qtr_total
----------- ----------- -----------
1 500 200
2 400 NULL
What am I missing here?
TIA.
View 2 Replies
Jan 7, 2004
How do I create a query that emulates a mix of aggregate & ‘non-aggregate’ expressions. I am using the query as the rowsource for a list box in Access.
Here is my query:
strSql = "SELECT tblTestHeader.TestHdrUniq, tblTestHeader.TestDate, " _
& "'" & Forms("frmCompanySearch").[lstCompanySrch].Column(2) & "'" _
& " + ' ' + tblLoadCell.Abbrev + ' ' + tblTestHeader.CertNumSequence AS CertNum, " _
& "tblLoadCell.Description AS LoadCell, " _
& "tblTestType.Description AS Test, " _
& "tblTester.Sname + ', ' + tblTester.Gname AS Tester " _
& "FROM tblTestHeader INNER JOIN tblLoadCell ON " _
& "tblTestHeader.LoadCellUniq = tblLoadCell.LoadCellUniq INNER JOIN " _
& "tblTester ON " _
& "tblTestHeader.TesterUniq = tblTester.TesterUniq INNER JOIN " _
& "tblTestType ON " _
& "tblTestHeader.TestTypeUniq = tblTestType.TestTypeUniq " _
& "WHERE CompanyUniq = " _
& Forms("frmCompanySearch").[lstCompanySrch].Column(1) _
& " ORDER BY tblTestHeader.TestDate, CertNum"
I want to include another column:
max(tblTestDetail.CertChar) as LastChar
but must have all or no aggregate expr. What is work around for this ?
View 1 Replies
View Related