We help IT Professionals succeed at work.
Get Started

MYSQL temporary table

michael789
michael789 asked
on
424 Views
Last Modified: 2021-04-21
I need to create a temporary table using mysql in order to change my data layout. My table includes data per month if a salary was paid or not for a specific month (INT 1 or 0). The field lohn1, lohn2, lohn3 etc. just has the value 0 or 1 based on if a salary was paid or not and the field lohn1m, lohn2m, lohn3m etc. just holds the month number it corresponds to. e.g. 1,2,3 etc.

CREATE TABLE `listmain` (
  `id_list` bigint(11) NOT NULL auto_increment,
  `lohn1` int(1) default '0',
  `lohn1m` int(11) default '1',
  `lohn2` int(1) default '0',
  `lohn2m` int(1) NOT NULL default '2',
  `lohn3` int(1) default '0',
  `lohn3m` int(1) NOT NULL default '3',
  `lohn4` int(1) default '0',
  `lohn4m` int(1) NOT NULL default '4',
  `lohn5` int(1) default '0',
  `lohn5m` int(1) NOT NULL default '5',
  `lohn6` int(1) default '0',
  `lohn6m` int(1) NOT NULL default '6',
  `lohn7` int(1) default '0',
  `lohn7m` int(1) NOT NULL default '7',
  `lohn8` int(1) default '0',
  `lohn8m` int(1) NOT NULL default '8',
  `lohn9` int(1) default '0',
  `lohn9m` int(1) NOT NULL default '9',
  `lohn10` int(1) default '0',
  `lohn10m` int(1) NOT NULL default '10',
  `lohn11` int(1) default '0',
  `lohn11m` int(1) NOT NULL default '11',
  `lohn12` int(1) default '0',
  `lohn12m` int(1) NOT NULL default '12',
  PRIMARY KEY  (`id_list`),

Now I need to take this values and run a query to create a temporary table that has the following structure:

id_temp_table (autoincrement)
month_number (which is the specific number of the month stored in lohn1m etc.)
value_salary (which hold for the specific month the  = 1)

So pretty much all values where a salary is selected/checked need to go into this table

Thank you for your help
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE