You can not use a column correlation name in other expressions, except in the order by clause.
The general technique is
select a + b
from (select <expression> as a, <expression> as b, ...
from ...) dt
It's called overlay in standard SQL. It has the bloated syntax
OVERLAY(<expression> PLACING <expression>
FROM <numeric value expression>
[FOR <numeric value expression>])
I haven't seen any DBMS with support for this.
Use of ` is not ANSI SQL compliant.
@lastID:=LAST_INSERT_ID() is not ANSI SQL compliant.
@ is not a valid character in an identifier.
LAST_INSERT_ID is a Mysql specific routine.
; is only used as delimiter between statements, not as a terminator.
If you have the data
dateColumn | rateColumn
------------------
2006-04-23 | 1234
2006-04-23 | 5678
what result do you want? It is not clear from your post.
SELECT SUM(pointsrecvd),userid
FROM tblPointSystem
group by userid
order by 1 desc
1 reflects the position in the select list of the item you wish to order by.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.