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

  • Home
  • SEARCH
  • 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 8694757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:51:38+00:00 2026-06-13T00:51:38+00:00

Is it possible to do several aggregate functions inside a single query I know

  • 0

Is it possible to do several aggregate functions inside a single query

I know whe can use

SELECT SUM(value) FROM mytable WHERE date  between '2012-05-01' AND '2012-06-01'

I’ve been trying to make an example

CREATE TABLE mytable
    (id varchar(10), value int, `date` date, situation varchar(10) ) ;

INSERT INTO mytable
    (id, value, date, situation)
VALUES
    ('id0', 1338, '2012-05-14','Urgent'),
    ('id0', 3572, '2012-05-13','Urgent'),
    ('id0', 3232, '2012-05-06','Urgent'),
    ('id0', 3068, '2012-05-05','Post'),
    ('id0', 3363, '2012-05-04','Urgent'),
    ('id0', 2022, '2012-04-28','Anual'),
    ('id0', 3193, '2012-04-24','Post')

But is it possible to use the same query to get other aggregate values?

SELECT SUM(value),SUM(value),Count(*) FROM mytable WHERE date  between '2012-05-01' AND '2012-06-01', WHERE date  between '2012-05-01' AND '2012-10-01', Where situation like 'Urgent' 

instead of 3 queries:

SELECT SUM(value) FROM mytable WHERE date  between '2012-05-01' AND '2012-06-01'
SELECT SUM(value) FROM mytable WHERE date  between '2012-05-01' AND '2012-10-01'
SELECT Count(*)   FROM mytable Where situation like 'Urgent'
  • 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-13T00:51:40+00:00Added an answer on June 13, 2026 at 12:51 am

    use case

    select
        sum(case when date between '2012-05-01' AND '2012-06-01' then value else 0 end) as sum1,
        sum(case when date between '2012-05-01' AND '2012-10-01' then value else 0 end) as sum2,
        sum(case when situation like 'Urgent' then 1 else 0 end) as count1
    from mytable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have several consumers listening on a single MSMQ instance and
I have several possible files which could hold my data; they can be compressed
I'm writing a function which will eventually use one of several possible cursors, for
The documentation for ref() mentions several possible return values. I understand most of them,
Is it possible to compose several fragment shaders in sequence under GLSL ES? I
Possible Duplicate: jquery data selector I have several elements with class 'connection_name'. Each one
Is it possible to build balancer trees with several levels in mod_jk configuration? for
Is it possible to make a command return several attributes and then assign each
I'd like to combine several queries into as few as possible. This is for
Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at

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.