Hello. Tell me. There is a table that is generated in SQL format.

код товара | наименование | закуп | прод| 001 | товар1 | 5 | 4 | 

The first two columns in the row are displayed in my usual Select, and where the purchase and prol is considered the sum in other tables and the total value is displayed.

  SELECT COALESCE(SUM(quant), 0.0) AS quant FROM paid_items, paid WHERE paid.record_type=-1 

One column counts -1, the second +1. I want to be sorted as a result of the third column. From more to less, but I can’t understand how to correctly specify sorting, I tried to thrust this condition completely into ORDERS BY, but nothing, of course, helped

  • one
    Do you need grouping or sorting? - Firepro
  • Please formulate the correct question. So far, he is in the form of "how do I organize a walk on the floor, if I like tomatoes?" - Denis
  • wrong sorting of course - Sergey
  • 2
    You need to write ORDER BY COALESCE(SUM(quant), 0.0) - vikolyada
  • See, there is a table that is generated in SQL format item code | name | purchase | prod | 001 | item1 | 5 | 4 | The first two columns in the row are displayed in my usual Select, and where the purchase and prol is considered the sum in other tables and the total value is displayed. And I want it sorted by this amount. From more to less - Sergey

0