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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:58:13+00:00 2026-05-16T20:58:13+00:00

I have a table like this named Days Day 1 Day 2 Day 3

  • 0

I have a table like this named “Days”

Day 1    Day 2    Day 3    Day 4    Day 5    Day 6    Day 7
1        1        1        1        0        0        0
1        1        1        1        0        0        0

which has the corresponding details. Where 1 is ‘true’ and 0 is false.

DaY 1 - sunday
day 2- monday
day 3 - tuesday
day 4- wednesday
day5 - thursday
day 6 - friday
dayy 7- saturday

1 - denotes there is work on the given day
0 - denotes there is no work on the given day.

Given the details above i need to make column to table mapping
and need to generate a table like this , where i need to get the data only those which has flag 1

1   Sunday 
2   Monday 
3   Tuesday     
4   Wednesday

for the first record.

  • 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-16T20:58:14+00:00Added an answer on May 16, 2026 at 8:58 pm

    I believe you’re looking for something like the following:

    select 
    case when day1=1 then '1 Sunday' end Sunday,
    case when day2=1 then '2 Monday' end Monday,
    case when day3=1 then '3 Tuesday' end Tuesday,
    case when day4=1 then '4 Wednesday' end Wednesday,
    case when day5=1 then '5 Thursday' end Thursday,
    case when day6=1 then '6 Friday' end Friday, 
    case when day7=1 then '7 Saturday' end Saturday
    from [table]
    where day1+day2+day3+day4+day5+day6+day7 <> 7
    

    Or those should be rows? Then you would need to unpivot the source data first like so:

    select     
    cast(substring(dayname, 4, 1) as tinyint) as DayNumber, 
    case cast(substring(dayname, 4, 1) as tinyint) 
    when 1 then 'Sunday'
    when 2 then 'Monday'
    when 3 then 'Tuesday'
    when 4 then 'Wednesday'
    when 5 then 'Thursday'
    when 6 then 'Friday'
    when 7 then 'Saturday' end [DayName]
    , DayFlag 
    from (select * from [table] t where day1+day2+day3+day4+day5+day6+day7 <> 7) f
    unpivot 
    (
    DayFlag for DayName in ([day1], [day2], [day3], [day4], [day5], [day6], [day7])
    ) unpvt
    where DayFlag = 1 --is this what you need?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named visiting that looks like this: id | visitor_id |
I have a table named categories like this: id int(11) NO PRI NULL auto_increment
I have a table like this: name code group john 12 smith 15 how
Let's say I have a table like this: name | score_a | score_b -----+---------+--------
I have a table in mysql like this Name Result T1_09_03_2010 fail T2_09_03_2010 pass
i have a table like this one: -------------------------------- id | name -------------------------------- 1 |
I have a table like this (simplified): ID | Name | Parent --------------------------------- 1
If I have a table like this: CREATE TABLE sizes ( name ENUM('small', 'medium',
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The

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.