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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:08:56+00:00 2026-06-06T06:08:56+00:00

I am trying to get the sum(comprate) for only max(effdt) having max(id) from the

  • 0

I am trying to get the sum(comprate) for only max(effdt) having max(id) from the following query,

SELECT  id, employee_code, effdt, comprate
FROM         dbo.employees_compensation
WHERE     (employee_code = '000321514')
ORDER BY effdt desc, id desc

Result of above query is as follows,

id      employee_code   effdt                   comprate
1473433 000321514       2010-09-02 00:00:00.000 46000
1473432 000321514       2010-09-02 00:00:00.000 138000
1453627 000321514       2010-09-02 00:00:00.000 46000
1453626 000321514       2010-09-02 00:00:00.000 138000
1447165 000321514       2010-09-02 00:00:00.000 46000
1447164 000321514       2010-09-02 00:00:00.000 138000
1424948 000321514       2010-09-02 00:00:00.000 46000
1424947 000321514       2010-09-02 00:00:00.000 138000
1405789 000321514       2010-09-02 00:00:00.000 46000
1405788 000321514       2010-09-02 00:00:00.000 138000

I tried many queries but I am not getting the expected result. What I want is the top first two values from above result i.e,

id    employee_code effdt                   comprate
1473433 000321514   2010-09-02 00:00:00.000 46000
1473432 000321514   2010-09-02 00:00:00.000 138000

and then get the sum(comprate) from the above result i.e,

sum(comprate)
184000

Could you help me in getting the expected result? Thanks in Advance.

  • 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-06T06:08:58+00:00Added an answer on June 6, 2026 at 6:08 am

    How about the following?

    SELECT     SUM(comprate) AS ComprateSum
    FROM         (SELECT     TOP (2) id, employee_code, effdt, comprate
                           FROM          _Test
                           WHERE      (employee_code = '000321514')
                           ORDER BY effdt DESC, id DESC) AS derivedtbl_1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with this query trying to get a sum and a
I am trying to create a query that allows me to get the sum
Im trying to get the sum of a list from a web service. [WebMethod]
I am trying to get the sum hours for each month from a given
I'm getting the following error when trying to get the sum in this Linq
Trying to get a check sum of results of a SELECT statement, tried this
I'm trying to get a sum of a field cost from a page type
I'm trying to get the sum of all prime numbers from 0 to 2
i am trying to get the sum of even numbers from a recursive array
I have a report where I'm trying to get the sum of a dynamic

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.