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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:35:48+00:00 2026-06-11T12:35:48+00:00

I am trying to select 1 of 2 rate columns from a table based

  • 0

I am trying to select 1 of 2 rate columns from a table based on the day of the week that is being searched. I am attempting to use two tables for this query: a calendar table (table name=calendar, column name=caldates) which is strictly a list of dates where each row is a date between 2012-06-30 and 2014-05-31. I also have another table (table name=rates) that has 4 columns: start_date, end_date, weekday_rate, and weekend_rate.

Start_date      end_date     weekday_rate     weekend_rate
"2012-05-01"  "2012-06-30"        69              150
"2012-07-01"  "2012-08-31"        74              200
"2012-09-01"  "2012-11-14"        75              210
"2012-11-15"  "2013-01-31"        90              150

When a query is performed, the system needs to look up the correct rate. Right now my query looks like this:

SELECT  
    CASE cast(extract(dow from caldates) as int)
    WHEN '0'  then (select weekday_rate from rates)
    WHEN '1'  then (select weekday_rate from rates)
    WHEN '2'  then (select weekday_rate from rates)
    WHEN '3'  then (select weekday_rate from rates)
    WHEN '4'  then (select weekday_rate from rates)
    WHEN '5'  then (select weekend_rate from rates)
    When '6'  then (select weekend_rate from rates)
    End AS the_date_rate
FROM calendar WHERE caldates >= '2012-08-30' and  caldates <=  '2012-09-04' ;

When I run the query, I receive the error “ERROR: more than one row returned by a subquery used as an expression. “

I would like the output to display the range of dates as well as the rate associated with the date. The above example would look something like

caldates        the_date_rate
2012-08-30           74
2012-08-31           200
2012-09-01           210
2012-09-02           75
2012-09-03           75
2012-09-04           75

Any ideas?

  • 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-11T12:35:49+00:00Added an answer on June 11, 2026 at 12:35 pm

    This would be sufficient (also see if you really need quotes around the date-of-week value after when clause):

    SELECT  
        CASE 
            WHEN cast(extract(dow from caldates) as int) < 6  then weekday_rate
            ELSE weekend_rate
        End AS the_date_rate
    FROM 
        calendar 
    WHERE 
        caldates >= '2012-08-30' and  caldates <=  '2012-09-04' ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to select the last record from a table in MySQL using
I am trying to SELECT records from two MySql tables. I would like all
I'm trying to rate matches based on the number of words from the query
I am currently trying to use a bulk insert from a temporary table with
I am trying to retrieve 7 columns from my Pages table, however it comes
In trying to select elements that have any attributes, the following throws a jQuery
When trying to select fields from a subquery if ANY of the subqueries do
I am trying to select three values from xml document. I want to get
I am trying to select an object from this array and print all of
I'm trying to select all dom elements that have id=mydiv but exclude the ones

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.