Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:54:15+00:00 2026-06-17T19:54:15+00:00

I have a table with a bunch of columns. Three columns are integers, and

  • 0

I have a table with a bunch of columns. Three columns are integers, and are labeled consumption, consumption2, and consumption3.

I would like to select each full row of the table, but order the selection by the sum of the three consumption fields descending.

I can order by each consumption column individually

order by consumption3 desc, consumption 2 desc, consumption desc

but I would prefer to sum these values and then order by that summed value.

I can also write a 4GL program to do this, but am trying to solve this in SQL.

If I do this,

select  *
from    ws_bill
order by sum(consumption) + sum(consumption2) + sum(consumption3)

then Informix’s SQL wants every column in the group by list.

Is there an easier way to do this, or should I just write the program?

Versions of Informix SE/4GL running on Ubuntu 12.04

ics@steamboy:~/icsdev$ dbaccess -V
DB-Access Version 7.25.UC6R1 
Software Serial Number ACP#J267193
ics@steamboy:~/icsdev$ fglpc -V

Pcode Version 732-750

Software Serial Number ACP#J267193
ics@steamboy:~/icsdev$ 

Here is the table:

create table "ics".ws_bill 
  (
    yr char(2),
    bill_no integer,
    bill_month smallint,
    due_date date,
    tran_date date,
    prev_reading integer,
    curr_reading integer,
    consumption integer,
    consumption2 integer,
    consumption3 integer,
    water_charge money(10,2),
    sewer_charge money(10,2),
    other_charge decimal(10,2),
    curr_bal money(10,2),
    estimated char(1),
    prev_due_date date,
    time_billed datetime year to second,
    override char(1),
    curr_bal_save money(10,2)
  );
revoke all on "ics".ws_bill from "public";

create unique index "ics".ws_indx on "ics".ws_bill (bill_no,yr,
    bill_month);

This is the main cursor as denoted in the accepted answer for this post.

declare wb_cp cursor for
select  b.yr,b.bill_no,
        sum(b.consumption + b.consumption2 + b.consumption3) as adj_tot
into    cons_rec.* #defined record variable
from    ws_bill b
where   b.yr >= start_yearG and b.yr <= end_yearG
group   by b.yr, b.bill_no
order by adj_tot desc, b.yr desc, b.bill_no desc
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:54:17+00:00Added an answer on June 17, 2026 at 7:54 pm

    You are talking about summing three columns. This is a simple expression (consumption + consumption2 + consumption3). You do not need the sum(…) function unless you want to sum multiple rows that you are grouping together.

    So, you need something along these lines:

    select bill_no, bill_month, ..., (consumption + consumption2 + consumption3) as tot_sum
      from ws_bill
     order by tot_sum desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a table with five columns. Full select statement would be
I have a bunch of columns in MySQL Table T1 with names like A/B
I have a table containing a bunch of input fields, sort of like a
I have a table that has three columns. When the task was supposed to
I have a bunch of tables that have DateUpdated columns. How can I have
I have a table with 7 cells and a bunch of rows. I want
I have a table schema which is essentially a bunch of transaction info with
i have a table which contains a bunch of dynamically created radio button lists,
so I have this HTML table with a bunch of big numbers in it
I have a bunch of coordinates in my table grid with the following schema

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.