If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Merging two columns into one and therefore doubling rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-11-10, 14:11
Hydrogen666 Hydrogen666 is offline
Registered User
 
Join Date: Jun 2008
Posts: 6
Merging two columns into one and therefore doubling rows

So, I feel that I've missed something here but here goes...

If i have a table with two columns, how can I (using a query) pull those together to appear to be the same field... ?
Code:
col1	col2
1	2
3	4

to be

colX	colY
1	fromCol1
2	fromCol2
3	fromCol1
4	fromCol2

A fuller explanation of what I'm doing.... (it's not imperative that you read this bit!)


I have a system that monitors kids coming in and out of a nursery. The childrens "shifts" have a "start time" and "end time" already stored in data, and every other bit of the system likes these to be separate fields.

However I need to calculate how many staff are required at any one time. So my plan is to combine these start/end times into one field as above with the second column telling me if a child is going in/out. therefore using these piece of data i can iterate through the data and for each start/end point calculate how many children there will be.

Any other suggestions to solve this would be welcome. No doubt something will come to me if I just stop thinking about it.!

ta
Adrian
Reply With Quote
  #2 (permalink)  
Old 11-11-10, 14:15
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
you can do it with a single query, using your existing table

it needs a start/end time slice, though, to measure the number of kids

what would you like to use, every 15 minutes, half hour, or something?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-11-10, 15:08
Hydrogen666 Hydrogen666 is offline
Registered User
 
Join Date: Jun 2008
Posts: 6
Thanks

Hi, thanks for your suggestion.

That was my initial idea for doing this, but I was thinking rather than doing unnecessary calculations based on every 30 minute period, I should do that calculations based solely on when the number of children change throughout the day.

I think I may well use this 30 minute interval method unless I have a brainwave in my sleep tonight.

thanks again :-)
Reply With Quote
  #4 (permalink)  
Old 11-11-10, 15:17
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
well, holler if you would like to see the query

or go ahead and write your application code if you must ...

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On