SQL question

Results 1 to 2 of 2

Thread: SQL question

  1. #1
    Join Date
    Dec 1969

    Default SQL question

    Im a beginner at using SQL statements and am struggling to make one work. Any help you guys can give would be appreciated. I need to sort all the records in a table based on a calculation.<BR>For example: If a hockey team has 3 fields (Win, Loss, Tie) I need the SQL statement to sort the teams based on pts. win = 2 pt, tie = 1 pt. Is there a way to perform this calculation and sort the results in the SQL statement? Or do I need to have a field containing the points?<BR>Thanks for your help

  2. #2
    Join Date
    Dec 1969

    Default RE: SQL question

    select 2*win + tie as points,othercolumns<BR> from teams<BR> order by 1 desc<BR><BR>You can have arbitrary expressions in the select list. The as points is just to give this expression a name that can be used to reference this value, e.g. in a recordset.<BR><BR>Order by 1 desc means that the records will be sorted by the values in the first column in the select list in descending order

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts