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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:11:00+00:00 2026-06-13T19:11:00+00:00

I have two main questions on getting 2 set of tables. table : room_type

  • 0

I have two main questions on getting 2 set of tables.

table : room_type
rt_id   rt_title
1       Type A
2       Type B
3       Type C
4       Type D
5       Type E

Here is another table to come with.

table: rate_cost

id     rate hotel cost                      date
2999    7   1   4700-5400-6100-6600-7300    2012-11-01
3000    7   1   4700-5400-6100-6600-7300    2012-11-02
3001    7   1   4700-5400-6100-6600-7300    2012-11-03
3002    7   1   4700-5400-6100-6600-7300    2012-11-04
3003    7   1   4700-5400-6100-6600-7300    2012-11-05
3004    7   1   4700-5400-6100-6600-7300    2012-11-06
3005    7   1   4700-5400-6100-6600-7300    2012-11-07
3006    7   1   4700-5400-6100-6600-7300    2012-11-08
3007    7   1   4700-5400-6100-6600-7300    2012-11-09
3008    7   1   4700-5400-6100-6600-7300    2012-11-10
3009    7   1   4700-5400-6100-6600-7300    2012-11-11
3010    7   1   4700-5400-6100-6600-7300    2012-11-12
3011    7   1   4700-5400-6100-6600-7300    2012-11-13
3012    7   1   4700-5400-6100-6600-7300    2012-11-14
3013    7   1   4700-5400-6100-6600-7300    2012-11-15
3014    7   1   4700-5400-6100-6600-7300    2012-11-16
3015    7   1   4700-5400-6100-6600-7300    2012-11-17
3016    7   1   4700-5400-6100-6600-7300    2012-11-18
3017    7   1   4700-5400-6100-6600-7300    2012-11-19
3018    7   1   4700-5400-6100-6600-7300    2012-11-20
3019    7   1   4700-5400-6100-6600-7300    2012-11-21
3020    7   1   4700-5400-6100-6600-7300    2012-11-22
3021    7   1   4700-5400-6100-6600-7300    2012-11-23
3022    7   1   4700-5400-6100-6600-7300    2012-11-24
3023    7   1   4700-5400-6100-6600-7300    2012-11-25
3024    7   1   4700-5400-6100-6600-7300    2012-11-26
3025    7   1   4700-5400-6100-6600-7300    2012-11-27
3026    7   1   4700-5400-6100-6600-7300    2012-11-28
3027    7   1   4700-5400-6100-6600-7300    2012-11-29
3028    7   1   4700-5400-6100-6600-7300    2012-11-30
3028    8   2   4700-5400-6100-6600-7300    2012-11-01
3028    9   3   4700-5400-6100-6600-7300    2012-11-01

Each dash separated number is a rate cost regarding to each room type by its position. For example 4700 is a rate cost for Type A (rt_id=1), 5400 is Type B… 7300 is Type E(rt_id=5).

Now I’d like to create a result like following.

Day/Room type   Type A | Type B | Type C | Type D | Type E
1 Nov 2012      4700     5400     6100     6600     7300
2 Nov 2012      4700     5400     6100     6600     7300
3 Nov 2012      4700     5400     6100     6600     7300
4 Nov 2012      4700     5400     6100     6600     7300
...
30 Nov 2012     4700     5400     6100     6600     7300

I was made those result work in PHP but it cost seconds to complete. I’ve tried to do on my own but I lack of mySQL knowledge. So please enlighten me.

  • 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-13T19:11:01+00:00Added an answer on June 13, 2026 at 7:11 pm

    Split a string into columns:

    select date,
           substring_index(cost, '-', 1) type_a,
           case when cost regexp '.*-' then
                     substring_index(substring_index(cost, '-', 2), '-', -1)
                else ''
           end type_b,
           case when cost regexp '.*-.*-' then
                substring_index(substring_index(cost, '-', 3), '-', -1)
                else ''
           end type_c,
           case when cost regexp '.*-.*-.*-' then
                substring_index(substring_index(cost, '-', 4), '-', -1)
                else ''
           end type_d,
           case when cost regexp '.*-.*-.*-.*-' then
                substring_index(substring_index(cost, '-', 5), '-', -1)
                else ''
           end type_e
    from rate_cost;
    

    If you can modify the table design, it’s better to create multiple columns:

    create table rate_cost (
        id int,
        rate int,
        hotel int,
        cost_type_a int,
        cost_type_b int,
        cost_type_c int,
        cost_type_d int,
        cost_type_e int,
        date date);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding the design of two tables. Table 1: The main
I actually have two questions, the on in the title being the main one.
Here I am trying to implement the jQuery I have two main files one
Suppose I have two tables Main and Other like the following: Main +----------+-----------------------------------+ |
I have two MAIN DIVs inside a DIV which is a PART of the
I'd like to have two main classes (or more) with leiningen, and then be
Say you have two main-line branches that have been developed separately for a long
I have two panels: main_panel child_panel The main_panel layout is set using: main_panel.setLayout(flowlayout) I
I have two columns say Main and Sub . (they can be of same
I have two files 1 - index.php 2 - main.php index.php call to main.php

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.