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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:56:45+00:00 2026-06-14T06:56:45+00:00

I have a semi-complicated select statement that’s building a custom column in a query,

  • 0

I have a semi-complicated select statement that’s building a custom “column” in a query, and the results need to be filtered by the results of this column. Is there some way to refer to this column in a predicate? You’ll see what I would like to do commented out in the where clause, filtering on ‘On Sale’.

select
p.prod_id,
case
  when p.subtitle is null then p.title
  else concat(p.title, ': ', p.subtitle)
end as 'Title',
p.issue as 'Issue',
e.abbrv as 'Editor',
p.jobnum as 'Job Number',
p.price as 'Price',
ship.due_date as 'Ship Date',
case
  when pi.onsale_minus_ship_date is not null then ship.due_date + interval pi.onsale_minus_ship_date day
  else
    case
      when prs.days_for_shipping != 0 then ship.due_date + interval prs.days_for_shipping day
      else ship.due_date + interval 7 day
    end
end as 'On Sale',
sale.due_date as 'Bookstore On Sale'
from products p

join schedules ship on ship.prod_id = p.prod_id and ship.milestone = 49
left join schedules sale on sale.prod_id = p.prod_id and sale.milestone = 647
left join editors e on find_in_set(e.id, p.editor)
left join printing_info pi on pi.prod_id = p.prod_id
left join printers prs on prs.id = pi.printer

where p.prod_type in (2, 3, 5, 6) -- physical, non comics (trades, hc, etc.)
--and 'On Sale' >= '$start_date' + interval 2 month
--and 'On Sale' <= '$end_date' + interval 2 month

order by ship.due_date asc, p.title asc
  • 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-14T06:56:47+00:00Added an answer on June 14, 2026 at 6:56 am

    You can do your filtering in the HAVING clause – unfortunately, you can’t refer to column aliases in the WHERE clause.

    HAVING `On Sale` >= '$start_date' + interval 2 month
    AND `On Sale` <= '$end_date' + interval 2 month
    

    http://dev.mysql.com/doc/refman/5.0/en/problems-with-alias.html

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

Sidebar

Related Questions

I have a semi-complicated problem and hoping that someone here will be able to
I have 5 semi-transparent images in my application. I need to select one of
I have a semi-working example that you can look at. This appears to work
I have a semi-melted data frame that looks like this: head(final_melt) Group Source variable
We have semi-complicated expressions in the format: 25 + [Variable1] > [Variable2] We need
I have a semi-large web application that we run locally and I need to
I have a semi-complex application i'm building that has various wizards and screens. I
I have an entry.rb model and I'm trying to make a semi-complicated validation. I
I have a script that executes database queries, and I use semi-colons + new
I'm building a semi-elaborate RadGrid where within my NestedViewTemplate I want to have a

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.