PHP & MYSQL Order By Decimal Column -


i'm running simple mysql query , trying order data sale value... column in database set decimal(16,2) when data comes isn't sorted in order.

here code:

$query = " select *      , sum(sale_value)    sale   week_no = $today  group       user_id   order      sale_value desc ";   $result = mysql_query($query) or die(mysql_error()); // print out result while($row = mysql_fetch_array($result)){  echo "total ". $row['user_id']. " = &pound;". $row['sum(sale_value)']; echo "<br />"; } 

and here result get:

total 14 = £2195.77 total 62 = £865.01 total 52 = £2989.53 total 42 = £2689.47 total 51 = £894.51 total 48 = £962.09 total 39 = £1161.43 total 33 = £1341.49 total 1 = £5989.57 total 8 = £4937.48 total 59 = £1377.70 total 32 = £3063.06 total 41 = £1937.82 total 60 = £2981.01 total 53 = £1050.21 total 46 = £1836.05 total 57 = £310.43 total 19 = £2534.92 total 5 = £1946.01 total 56 = £471.00 total 7 = £865.00 total 2 = £754.30 

can spot i'm doing wrong?

you ordering arbitrary value in matching row, not sum. give column alias , use that:

select *, sum(sale_value) total_sale_value sale week_no = ".$today." group  user_id order total_sale_value desc; 

by way, select * really, really, bad idea use group by. should explicit list columns used define each aggregation group:

select user_id, sum(sale_value) total_sale_value sale week_no = ".$today." group user_id order total_sale_value desc; 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -