0

I need to group orders by date and sum the total,

My table looks like this :

TEST_DATE
TEST_ID - NUMBER
SUCC_ID - NUMBER

I need to group by date and sum the total, this is my query:

SELECT COUNT(*), TEST_ID, SUCC_ID
FROM MYTABS
GROUP BY TEST_DATE;

How can I?

thank you.

  • You want to sum the totals, but I can't see a total column – miracle173 Aug 20 '14 at 8:39
1

You can think of aggregate queries as two parts:

  • columns that are included in GROUP BY, and
  • columns that are included in aggregate functions, like SUM(), MAX(), COUNT(), etc.

To put things very simply, if the column is in the SELECT clause, it has to either appear in the GROUP BY or inside an aggregate function.

In your case, you're probably looking for this:

SELECT TEST_DATE,
       COUNT(TEST_ID) AS numberOfTestID,
       SUM(SUCC_ID) AS sumOfSuccID
FROM MYTABS
GROUP BY TEST_DATE;
| improve this answer | |
  • 1
    +1 , but I doubt that he is interested inthe sum of some IDs – miracle173 Aug 20 '14 at 8:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.