mysql - ungroup table, manipulate columns and convert to a row -


I have an Excel table of this structure (can be converted to XML or CSV):

  | License plate Parking | Fuel | Cleaning | --------------------------------------------- | 1111 AAA | 234 | 21 | 1244 | | 2222 AAA 22 | 12 | 644 | | 3333 BBB | 523 | 123 | 123 |  

For parking, fuel, etc. per car / month per month is spent.

There is a unique price in the license plate table.

I need to convert this table into MySQL to be imported into this table, but I do not know how to do this and which device is good for it:

  | License plate Concept | Zodiac ------------------------------------- | 1111 AAA | Parking | 234 | | 1111 AAA | Fuel | 21 | | 1111 AAA | Cleaning | 1244 | | 2222 AAA Parking | 22 | | 2222 AAA Fuel | 12 | | 2222 AAA Cleaning | 644 | | ....... | ........ | ..... |  

License plate is not a unique value in the results table, and it is repeated for the number of those concepts.

UPD: Just discovered that it might be (probably not at all) called denromalized data.

I will do this with MySQL in the following way:

Table (After converting into CSV) import into MySQL it is called

  Table Source (License_Plate four (7) primary key, parking Integer (8) unsigned, create fuel integer (8) unsigned, cleanup (8) unsigned); Load data INFILE ',' in the All Source field defined by 'path / per / file'.  

Create another table with the desired final structure, let's call it destination

  Destination (licensed four (7), concept varchar (10), zodiac int (8) unsigned);  

Display the following queries

  include the source from the included source in the destination License_Plate, the form of 'parking' concept In License_Plate, the 'fuel' concept in the parking destination, the source from the source insert in the destination as the source of the fuel, as the source from the selection source, license_Plate, as a 'cleanup' concept, select cleaning  

Things to consider:

  1. I have a primary key Has declared License_Plate in the form, just depending on your example. This can not be the case if it repeats in the actual data. Also, if you have more than one line on the source table for the same license plate, then you may need to adjust my 3 questions for the total values.
  2. In addition, datatype sampling data is adjusted, for example, if you have more than 8 digits, then it may need to be changed.
  3. One way in which you can upload your CSV, there are several options in it, you should check them, you can do it with some tools, so that you do not have to write that statement.
  4. Last, those table names were selected as an example, you should come up with better people, who represent your problem domain. / Li>

Hope this helps you.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -