Re: ORDER PROBLEMS

From: Date: Wed, 16 May 2001 02:01:01 +0000
Subject: Re: ORDER PROBLEMS
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-52972@lists.php.net to get a copy of this message
Rafael, Couple of things ... see below. I'm doing this without checking the MySQL docs, so validate this against them. At 08:22 PM 5/15/01 -0300, Rafael Faria wrote:
Hello Guys, i'm with problems.... first i try to add a value like "8.55" into my sql data base that was set up to DOUBLE (10,0) and isn't work... i don't know how this work... but i'm here to ask for someone explain me.
Try DOUBLE(10,2), that will provide for the decimal places.
well... i did with varchar to add this value as i want to.. do i have a lot of values like
votes          average
  2                 8.5
  10               5.5
  1                 10
  20                5.1
and i wanna sort by votes and average.... have someway to do that?
Generally, when you store numeric values in a character field, you have to left pad them with zeroes otherwise you get strange ordering behaviour. If you want to do arithmetic on these values, don't store them as characters, store them as one of the numeric types. If you store numbers as characters, don't waste space with varchar, use a straight char type. As for ordering, that is a function of your SELECT statement. Example: " select * from vote_results order by votes " will order results by an ascending count of votes. " select * from vote_results order by votes desc " will order results by a descending count of votes. " select * from vote_results order by votes, average " will order results by an ascending count of votes and then by ascending averages within the returned set. (I don't know what the point of this would be.) A comment on your average field. Databases can calculate averages _very_ quickly and it may be better to do that in your SELECT statement. Heres an extract from the manual: AVG(expr)
    Returns the average value of expr:
    mysql> select student_name, AVG(test_score)
               from student
               GROUP BY student_name;
Hope you find this helpful - Miles Thompson PS "br" - Brazil? I'm not up on my country codes.

« previous php.general (#52972) next »