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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:13:01+00:00 2026-06-17T11:13:01+00:00

The below SQL query sums up each penalty mark per question in a session:

  • 0

The below SQL query sums up each penalty mark per question in a session:

SELECT s.SessionId,q.QuestionId,SUM(pm.PenaltyMarks)
    FROM Session s
    INNER JOIN Question q ON s.SessionId = q.SessionId
    INNER JOIN Penalty_Marks pm ON q.QuestionId = pm.QuestionId
    WHERE (s.SessionId = 30)
    GROUP BY s.SessionId,q.QuestionId

Below is what the output displays:

SessionId  QuestionId  Sum(pm.PenaltyMarks)
30         77          4
30         38          3
30         39          4

But what I want to happen is now sum up all of the penalty marks within the Session. So in the above example it will add up the penalty marks together for session 30 to output the total penalty marks as 11. But my question is how can this be achieved?

So below is what it should look like:

SessionId  TotalPenaltyMarks
30         11
  • 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-17T11:13:03+00:00Added an answer on June 17, 2026 at 11:13 am

    remove q.QuestionId

    SELECT  s.SessionId, 
            SUM(pm.PenaltyMarks) TotalPenaltyMarks
    FROM    Session s
            INNER JOIN Question q ON s.SessionId = q.SessionId
            INNER JOIN Penalty_Marks pm ON q.QuestionId = pm.QuestionId
    WHERE   s.SessionId = 30
    GROUP   BY s.SessionId
    

    The GROUP BY clause is already optional since you are already filtering for a specific SessionId.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my SQL query used in SSRS report SELECT Claimname,CONVERT(VARCHAR,ClaimResponsedate,101) FROM Claim WHERE
How can I write below sql query in linq select * from Product where
I need to convert the below SQL query into HQL query. select * from
Consider the SQL query below: SELECT * FROM opening_hours WHERE week_day = WEEKDAY(NOW()) +
I have the below SQL query: SELECT g.name AS gname, COUNT(u.id) AS noMembers, f.name
I want to write the below SQL query in HQL - select * from
I tried the below sql query INSERT INTO test.ACT_QUERY values(2139,2,'SELECT ''D'',ORDER_ID from dual'); When
I've got the SQL query below: SELECT message, sent_date, user_id FROM messages LEFT JOIN
I want an equivalent linq to object query for the below sql query SELECT
consider my sql query below; it is calling sum twice for the same argument.

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.