Results 1 to 4 of 4
Apr 29, 2003, 04:34 #1
column type changes in query result
i'm didn't find it in my mysql reference ( at least for now ) so asking here...
I want to change the type of a result column of a query in mysql.
Basicly I have such a query:
SELECT ( column1 / column2 ) AS result FROM table ORBER BY result DESC
to be exactly clear:
now it returns like this:
5.30 and so on...
I want to have such results:
I could use some expert help here . Thanks in advance...
Apr 29, 2003, 05:25 #2
- Join Date
- Apr 2003
- Needham, MA
- 0 Post(s)
- 0 Thread(s)
Use the CAST or CONVERT function
Use the CAST or CONVERT function, or just add the calculated result to zero and it should remain an integer.
SELECT (0 + (column1 / column2) ) AS result FROM table ORBER BY result DESC
May 3, 2003, 04:02 #3
nope. still doesn't work. the null value in RESULT is still before the other values in DESC. Also my host has mysql 3.23 which doesn't support CAST function
May 3, 2003, 06:25 #4
- Join Date
- Jul 2002
- Toronto, Canada
- 52 Post(s)
- 2 Thread(s)
if you want nulls to come last, you have to add another sort column
if you don't mind nulls showing as zero, then they will come last if you writeCode:
select case when column1=0 or column2=0 then 0 else column1 / column2 end as result from yourtable order by result desc