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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:34:15+00:00 2026-06-04T17:34:15+00:00

Here’s the situation. I created a view that has all the following information CREATE

  • 0

Here’s the situation. I created a view that has all the following information

CREATE VIEW view2 AS
SELECT activity_id,
       subject_code,
       academic_period_code,
       DATEDIFF(HOUR,time_start,time_end) AS duration
FROM   activity

Okay, now I’m trying to make a query that can produce two columns,
1. one with subject code and the academic_period code concatenated into one column
2. The second column contains the total number of duration for each subject that is in that academic period

So its like: CS123 in academic_period 121 has total of 5 hours activity. I’m fine with the first column but I’ve been wondering how do I get the 2nd column. If I use the SUM function it just totals up the column itself so I’m not sure how to deal with this.

Sample data

Subject Code   Activity_code    Academic_Period_Code   Duration
CS123          1                 121                   2
CS123          2                 121                   3
CS123          3                 122                   2
CS123          4                 122                   2

What I have done?]

SELECT subject_code + academic_period_code AS subject,
       (I think I have to do a subquery but I'm not sure how its suppose to work out) AS total_activity_time

FROM view2

  • 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-04T17:34:17+00:00Added an answer on June 4, 2026 at 5:34 pm

    Assuming SQL Server and that I understand what you are looking for:

    select
        subject_code + academic_period_code as [Type],
        sum(duration) as duration
    from view2
    group by
        subject_code + academic_period_code;
    

    should get you where I think you’re trying to get.

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

Sidebar

Related Questions

Here's a query that works fine: SELECT rowid as msg_rowid, a, b, c FROM
Here the total height of all <div> 's are 900 pixels, but the jQuery
Here's the deal: I'm in the process of planning a mid-sized business application that
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
Here's my procedure: DROP PROCEDURE IF EXISTS `couponExpires`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `couponExpires`(IN couponID BIGINT,
Here is my problem : I have a post controller with the action create.
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the problem that I am trying to solve. I have two folders

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.