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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:12:32+00:00 2026-05-29T16:12:32+00:00

I often have to write queries with a fairly complex, constructed column that I

  • 0

I often have to write queries with a fairly complex, constructed column that I will aggregate by. For example:

SELECT  
EXTRACT(week FROM to_timestamp("Date Created"/1000)) AS week
...

I know that you cannot use aliases in the GROUP BY clause (this Why doesn't Oracle SQL allow us to use column aliases in GROUP BY clauses? question explains logically why), but is there anything else I can do other than re-doing the column calculation, or am I stuck with this:

SELECT COUNT(*), EXTRACT(week FROM to_timestamp("Date Created"/1000)) AS week
FROM mytable
GROUP BY EXTRACT(week FROM to_timestamp("Date Created"/1000))
  • 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-29T16:12:33+00:00Added an answer on May 29, 2026 at 4:12 pm

    Often, I break complexity by using sub-queries.

    select count(*), week
    from
    (
        SELECT EXTRACT(week FROM to_timestamp("Date Created"/1000)) AS week
        FROM mytable
    ) sel
    GROUP BY week
    

    Divide and conquer approach has paid off pretty well so far.

    Update

    Alternatives to solving this issue:

    1. Computed columns (as @gbn stated in his answer).

      • Pros:
        • You can declare a column that’s pretty much used in most queries
        • Some RDBMs allow you to create an index over a computed column (pretty important for performance)
      • Cons:
        • not all RDBMs provide computed columns
        • You might end up declaring a column that’s used in one very specific query (out of the thousands of queries you have in your system). Someday, this query will have changed and the column will just sit there…
    2. CTEs

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

Sidebar

Related Questions

I'm using Squirrel SQL with Oracle. I often have to write quick queries for
I'm trying to write a sql query that shows how often two teams have
I often have to write code in other languages that interact with C structs.
Often during writing JavaScript, we have to write configuration object. For example Ext.define('User', {
I noticed that a lot of tutorial instructions often have this code: $sql=SELECT *
I often have data in Excel or text that I need to get into
I often have a subroutine in Perl that fills an array with some information.
I often have to deal with XML documents that contain namespaced elements, but doesn't
I have found that I often have to implement some sort of a scheduler
I prefer to develop with E_NOTICES turned on, but I often have to write

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.