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.

closed as unclear what you're asking by Mark Storey-Smith, Paul White, Max Vernon, RolandoMySQLDBA, Leigh Riffel Sep 26 '14 at 19:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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;
  • 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.