Question about a query
Posted in 1995
Hi all...
I'm trying to make some sense out of how Informix does grouping.
It looks like there are times that I phrase the same query 2
different ways and get 2 different results. Here's an example:
Given this table (named "dp"):
*****
Column name Type Nulls
a integer yes
b integer yes
c integer yes
*****
with this data:
*****
insert into dp values (1,2,1);
insert into dp values (1,2,2);
insert into dp values (2,1,1);*****
these queries:
*****
select a,b,sum(a),(a-b) from dp group by a,b;
select a,b,sum(a),(a-b) from dp group by 1,2;
select a,b,sum(a),(a-b) from dp group by 1,2,4;*****
return these results:
*****
a b (sum) (expression)
1 1 2 0
2 1 2 1
a b (sum) (expression)
1 2 2 0
2 1 2 1
a b (sum) (expression)
1 2 2 -1
2 1 2 1
2 row(s) retrieved.
*****
All the above stuff was cut from an isql session. There are
several things about these results that don't make sense to me:
1) Why do queries 1 & 2 give different results? I thought that
using the position numbers was just a shorthand way of referring
to the columns.
2) Where does the first row in the output of query #1 come from?
There are no rows in the table with a=1 and b=1!
3) Why is the math in #2 inconsistent with the rest of the data?
(1-2!=0)
4) The third query is the only one that gives the results I
expected. Why does grouping by a computed column (which is changing
with every group of a & b in this case) change the results?
FWIW, tbstat -V reports 5.02.UC6; isql -V says 4.11.UC1. The results
are the same with dbaccess and 4gl.
Thanks in advance for any answers/thoughts/hints...
--
---
- Derrek (dirk@xmission.com)