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 7507469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:29:35+00:00 2026-05-29T22:29:35+00:00

I hava following sql query SELECT animal_code, ISNULL(SUM(calve_milk + morning + evening), 0) /

  • 0

I hava following sql query

SELECT animal_code, ISNULL(SUM(calve_milk + morning + evening), 0) / 30 AS [Sep 2011],
                          (SELECT     ISNULL(SUM(calve_milk + morning + evening), 0) / 31 AS Expr1
                            FROM          dbo.Status
                            WHERE      (m_date BETWEEN '10/1/2011' AND '10/31/2011')) AS [Oct 2011]
FROM         dbo.Status AS Status_1
WHERE     (m_date BETWEEN '9/1/2011' AND '9/30/2011')
GROUP BY animal_code
ORDER BY animal_code

Through this query I have calculated a sum between a date range and named it as [Sep 2011] and now i have to calculate the [oct 2011] sum grouping it by animal code but i think the fixed column is only possible in subquery but in subquery i am unable to group the sum by animal code please any one help me out to get that sum group by animal_code in subquery

Update

select a.animal_code,a.Sep2011,b.Oct2011 from 
(SELECT DISTINCT   Images.animal_code, 
REPLACE(REPLACE(ROUND(ISNULL(SUM(Status.calve_milk + Status.morning + Status.evening), 0) / 30, 0), '.', ''), '0', '') Sep2011
FROM Images,Status,animal_Status
where Images.animal_code=Status.animal_code
and     Images.status_id=animal_status.status_id
and status.m_date between '9/1/2011' and '9/30/2011'
and animal_status.status_id=8
group by animal_code) a,
(SELECT DISTINCT   Images.animal_code, 
REPLACE(REPLACE(ROUND(ISNULL(SUM(Status.calve_milk + Status.morning + Status.evening), 0) / 31, 0), '.', ''), '0', '') Oct2011
FROM Images,Status,animal_Status
where Images.animal_code=Status.animal_code
and     Images.status_id=animal_status.status_id
and status.m_date between '10/1/2011' and '10/31/2011'
and animal_status.status_id=8
group by animal_code) b
where a.animal_code=b.animal_code
  • 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-05-29T22:29:36+00:00Added an answer on May 29, 2026 at 10:29 pm

    I am afread that you haven’t seen my last comment

    Ok i simulate your table, i make this smart query (i guess 🙂 ):

    SELECT  septable.code, septable.sep, octtable.oct
    FROM    (SELECT  code, ISNULL(SUM(mor + milk + ev), 0) / 30 AS sep
                 FROM    status
                 WHERE  (m_date BETWEEN '09/01/2011' AND '09/30/2011')
                 GROUP BY code) AS septable INNER JOIN
                    (SELECT  code, ISNULL(SUM(mor + milk + ev), 0) / 31 AS oct
                    FROM     status AS status_1
                    WHERE  (m_date BETWEEN '10/01/2011' AND '10/30/2011')
                    GROUP BY code) AS octtable ON octtable.code = septable.code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hava the sql as below: select a.dept, a.name from students a group by
I hava a listview like the following. The text in the TextView comes from
I hava a stored procedure named PROC_fetchTableInfo (simple select from sys.tables) in a database
I hava a data window object, in which I am fetching some attributes from
i hava a placed a select statement inside a table cell. The ui was
I hava a Transaction datatable with Amount field. I want to get Sum (Amount)
I hava read from Khalid Mugal and others that the conditional operator is right
i hava a set of following tables customer(cus_id,cus_name); jointAccount(cus_id,acc_number,relationship); account(acc_number,cus_id) now i want to
I hava a problme to make a query. This query which I created WITH
I hava a PHP script which generates a PDF file (i'm using fpdf from

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.