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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:42:34+00:00 2026-06-09T03:42:34+00:00

I have this huge ugly query below, i’d like to sort by it in

  • 0

I have this huge ugly query below, i’d like to sort by it in a catalog view. Thinking something like http://wow.dev:3000/catalog_items?&order=deals. A million thank yous in advance for any comments or answers.

select 100 - round((current_price / item.estimated_price)*100) as percent, item.cached_thumbnail_url, item.item_id, it.name,
          ci.current_price, ci.close_date
           from item
           join catalog_item ci on ci.item_id = item.item_id
           join item_translations as it on (it.item_id = item.item_id)
           where  (100 - round((current_price / item.estimated_price)*100)) > 49 and 
           item.estimated_price > 0 and ci.current_price > 0 and ci.close_date > now() and item.active = 1 and ci.active = 1 and 
           (current_price / estimated_price) < 1
           order by (ci.close_date < DATE_ADD(now(), INTERVAL 17 hour))  and (item.estimated_price - current_price) desc
           limit 12
  • 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-09T03:42:35+00:00Added an answer on June 9, 2026 at 3:42 am

    Not sure how this could be related to ROR, but anyways:

    1. You have 100 - round((current_price / item.estimated_price)*100) as percent in your SELECT clause, yet anyway using the same expression in WHERE conditions.

    2. Can item.estimated_price be less than zero? If not the item.estimated_price > 0 condition is excessive, if it’s zero the (100 - round((current_price / item.estimated_price)*100)) > 49 condition will be false

    3. The (current_price / estimated_price) < 1 is excessive for same reasons

    So you query can be rewritten a bit more clearly like this:

    select (100 - round((current_price / item.estimated_price)*100)) as percent,
       item.cached_thumbnail_url, item.item_id, it.name,
       ci.current_price, ci.close_date
    from item
       join catalog_item ci on ci.item_id = item.item_id
       join item_translations as it on (it.item_id = item.item_id)
    where
       percent > 49
       and ci.current_price > 0
       and ci.close_date > now()
       and item.active = 1
       and ci.active = 1
    order by
       (ci.close_date < DATE_ADD(now(), INTERVAL 17 hour))
       and (item.estimated_price - current_price) desc
    limit 12
    

    This doesn’t improve the situation a lot, but I can’t say more without knowing any more reasons about your DB architecture.

    BTW the link in your question doesn’t work (it’s you local link obviously)

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

Sidebar

Related Questions

I have a huge string that looks like this: Text Text Text Text Text
I have this huge domain object(say parent) which contains other domain objects. It takes
i have this dictionary: a) 2012 UN NEWNW = ( 2012/06/04 Saudi Arabia Huge
I have a huge problem with this method im trying to make. I have
I had a huge file for creating this GUI and I have shortened it
I have a huge autocomplete field with a list of exams. This field prepends
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I have this huge data frame that has servernames, Date, CPU, memory as the
I have this huge RegEx for matching credit cards numbers. But its PCRE. Works

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.