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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:17:40+00:00 2026-06-09T22:17:40+00:00

I have this table: | DAY | TRIMESTER | Day is an integer value,

  • 0

I have this table:

| DAY | TRIMESTER |

Day is an integer value, always increasing (it counts the seconds passing from day 0). TRIMESTER contains a String value (‘FIRST’,’SECOND’,’THIRD’,etc). I need to get the list of trimesters in the right order.

SELECT DISTINCT TRIMESTER FROM table

returns:

| TRIMESTER |
|   FIRST   |
|   THIRD   |
|   SECOND  |

I have assessed that this would solve my problem:

SELECT  DISTINCT TRIMESTER, SUM(DAY) FROM table GROUP BY TRIMESTER ORDER BY SUM(DAY)

Is there a nicer solution which would output what I need and that would require less computing done by the database? The database is Oracle 11g and the tables are supposed to become very big.

SAMPLE DATA:

| DAY | TRIMESTER |
|  0  |  FIRST    |
|  10 |  FIRST    |
|  12 |  FIRST    |
|  20 |  FIRST    |
|  30 |  SECOND   |
|  35 |  SECOND   |
|  46 |  THIRD    |

I need to get in order: ‘FIRST’,’SECOND’ and ‘THIRD’. Anyway I have no control over the keys in the TRIMESTER column. They are strings and might just be any string, I can’t order them by name. I only know that they cover a “range” of DAY values. E.g. if I had values of “DAY” between 31 and 34 in the example, they’d all have a “SECOND” value in the trimester column.

  • 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-09T22:17:42+00:00Added an answer on June 9, 2026 at 10:17 pm

    Using GROUP BY:

    select TRIMESTER 
    from MyTable 
    group by trimester 
    order by max(DAY)
    

    SQL Fiddle Example #1

    Using RANK and PARTITION:

    SELECT TRIMESTER
    FROM (
      SELECT TRIMESTER,
      RANK() OVER (partition by TRIMESTER ORDER BY DAY DESC) DAYRANK
      FROM MyTable)
    WHERE DAYRANK = 1;
    

    SQL Fiddle Example #2

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

Sidebar

Related Questions

I have this information from a Table: The due date day and month (eg.
I have a table that someone update this table every day. I would like
I have been struggling with this all day. I have an html table in
I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have this MySQl database that has a table which contains a column that
I have a table with value look like this id time_stamp value 1 2013-01-01
I have a table that seems like this: +-----+-----------+------------+ | id | value |
We have a (currently InnoDB) table which contains roughly 500,000 rows. This represents a
I have a table called orders this table contains all the information we need.
I have a table that contains approx 10 million rows. This table is periodically

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.