Subject | Grouping on a calculation |
---|---|
Author | Rick Debay |
Post date | 2006-01-20T21:23:53Z |
This works:
SELECT
t.COL_1/100, MIN( t.COL_2 )
FROM
TABLE_1 t
GROUP BY
1
This doesn't:
SELECT
t.COL_1/100, MIN( t.COL_2 )
FROM
TABLE_1 t
GROUP BY
t.COL_1/100
Dynamic SQL Error SQL error code = -104 Token unknown - line 1, char 171
(
I can't use the first way, as I need to determine what value of t.COL_1
is associated with the minimum value, and the WHERE clause would contain
t.COL_2 = (SELECT MIN( t.COL_2 ) FROM TABLE_1 t GROUP BY t.COL_1/100)
among other conditionals.
So my question is, why doesn't the second query work, and is there
anything that would solve my requirement of finding out what row had the
minimum value?
Thanks, Rick DeBay
SELECT
t.COL_1/100, MIN( t.COL_2 )
FROM
TABLE_1 t
GROUP BY
1
This doesn't:
SELECT
t.COL_1/100, MIN( t.COL_2 )
FROM
TABLE_1 t
GROUP BY
t.COL_1/100
Dynamic SQL Error SQL error code = -104 Token unknown - line 1, char 171
(
I can't use the first way, as I need to determine what value of t.COL_1
is associated with the minimum value, and the WHERE clause would contain
t.COL_2 = (SELECT MIN( t.COL_2 ) FROM TABLE_1 t GROUP BY t.COL_1/100)
among other conditionals.
So my question is, why doesn't the second query work, and is there
anything that would solve my requirement of finding out what row had the
minimum value?
Thanks, Rick DeBay