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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:31:00+00:00 2026-05-26T09:31:00+00:00

I have this query SELECT semester, COUNT(id) AS total, RIGHT(RTRIM(semester), 4) AS year FROM

  • 0

I have this query

SELECT semester, COUNT(id) AS total, RIGHT(RTRIM(semester), 4) AS year 
FROM TextbookReservation 
WHERE (semester IS NOT NULL) 
AND (semester <> '')
AND (semester <> 'SM2008') 
AND semester <> 'SU2008') 
GROUP BY semester ORDER BY year, semester DESC

Which produces something like this:

semester  total year
SP2006    2277  2006
FA2006    4367  2006
SP2007    2893  2007
FA2007    5624  2007
SP2008    4083  2008
FA2008    6451  2008

I would like to return something like this:

year  totalSpring totalFall
2006  2277        4367
2007  2893        5624
2008  4083        6451

Any ideas on how I can approach this query? Thanks!

  • 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-26T09:31:00+00:00Added an answer on May 26, 2026 at 9:31 am

    Without PIVOT tables, since you didn’t specify the version:

    SELECT [year], 
    sum(case WHEN left(semester,2)='SP' then total ELSE 0 END) as totalSpring ,
    sum(case WHEN left(semester,2)='FA' THEN total else 0 end) as totalFall
    from (
    
           SELECT semester
                , count(id) AS total
                , right(RTRIM(semester), 4) AS year
           FROM
               TextbookReservation
           WHERE
               semester IS NOT NULL
               AND semester <> ''
               AND semester <> 'SM2008'
               AND semester <> 'SU2008'
           GROUP BY
               semester 
    ) t
    GROUP BY t.[year]
    order by t.[year]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: SELECT COUNT(articles.id) AS count FROM articles, xml_documents, streams WHERE articles.xml_document_id
I have this query: SELECT `manufacturers`.*, `languages`.*, COUNT(`products`.`id`) AS productcount FROM (`manufacturers`) WHERE `manufacturers`.`flushed`
I have this query: SELECT COUNT( tbl_workstation.workstation_id ) AS AVAILABLE, tbl_lab.room_no, tbl_lab.capacity FROM tbl_workstation,
I have this query: select count(id) AS num,date_id from table where FROM_UNIXTIME(date_id,'%d-%m-%Y')='17-08-2009' order by
I have this query: select count (convert(varchar(50), TmpDate, 103 )),convert(varchar(50), TmpDate, 103 ) from
I have this query: SELECT device, COUNT(*) FROM database.table GROUP BY device HAVING count(*)
I have this query: SELECT foo.*, COUNT(archive.pkey) as archivedCount FROM ( SELECT type, count(active.pkey)
I have this query: SELECT count(member_id) FROM member_favorite_business WHERE business_id=3912 AND member_id=413 When I
I have this query: SELECT COUNT(*) AS `numrows` FROM (`tbl_A`) JOIN `tbl_B` ON `tbl_A`.`B_id`
I have this query: SELECT gamer_id,COUNT(*) AS sum, SUM(amount) as amount FROM sales_list WHERE

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.