Forum Moderators: open

Message Too Old, No Replies

MYSQL - Dynamic Column Type Change

MYSQL-Dynamic Column Type Change

         

php_hex

9:53 am on Aug 27, 2008 (gmt 0)

10+ Year Member



Hi,

I am trying to run one qeury in my Mysql Database to calculate Gross Profit nd Margins from few tables.

I'm selecting final value of gross profit in query like :

format(((prod.selling_price + ship.rate) - (prod.cost_price + ship.shipping_cost + sup.fee_per_order + sup.extra_fee_per_product + sup.other)),2) as gross_profit.

Now I want to sort results on this gross_profit ASC / DESC depends on requirement - when im doing sorting on this gross_profit its not giving accurate result coz its taking values of gross_profit as string.

Is ny way i can convert this gross_profit to INT so my sorting give accurate results or any other way to get accurate result in sorting?

I tried to use like ORDER BY CAST(gross_profit AS SIGNED) but not work as i understand its not column from table it self.

Can any one help me to sort out this?..

Thanks in Advance !

ZydoSEO

2:51 pm on Aug 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try:

ORDER BY (prod.selling_price + ship.rate) - (prod.cost_price + ship.shipping_cost + sup.fee_per_order + sup.extra_fee_per_product + sup.other)

I think that would fix it

It's sorting it as a String because the FORMAT() function is converting your DECIMAL? result to a String.

php_hex

6:26 am on Aug 29, 2008 (gmt 0)

10+ Year Member



Hey ZydoSEO

I got thing...thanks i have sorted out with your help..just need to remove FORMAT function and it works !

Thanks a lot !