multilevel/nested headers in CSV files - csv

How can I "make" multilevel/nested headers in CSV files please?
Example:
-----------------------------------------
| Big 1 | Big 2 |
-----------------------------------------
| Small A | Small B | Small C | Small D |
-----------------------------------------
| ... |

Related

remove duplicate headers in hive-beeline

Select ACCOUNT_NUMBER, BIN AS RISK_BIN FROM test.daily_call_routing2;"
| python -c 'exec("import sys;import csv;reader = csv.reader(sys.stdin,
dialect=csv.excel_tab);writer = csv.writer(sys.stdout,
dialect=csv.excel)\nfor row in reader: writer.writerow(row)")' >
$EXPORT_DIR//home/rabbid160/test_$DATE_STR.csv;**
When I'm trying to execute the above command in beeline-hive, I am able to see the data however with multiple headers in between. Can anyone please tell me how this can be solved to only one header and data following.
Example as follows:
+-------------------+-----------+--+
| account_number | risk_bin |
+-------------------+-----------+--+
| 8498310230444304 | 2 |
| 8778104140754717 | 2 |
| 8155100513664825 | 2 |
| 8155100513664825 | 2 |
| 8155400040004812 | 2 |
| 8155200521190266 | 2 |
| 8155300210482543 | 2 |
| 8497202241094288 | 2 |
| 8155500010197049 | 2 |
+-------------------+-----------+--+
| account_number | risk_bin |
+-------------------+-----------+--+
| 8155100030718781 | 2 |
| 8495444731138751 | 2 |
| 8498320015120250 | 2 |
| 8498330360083177 | 2 |
| 8155300210487112 | 2 |
| 8777701821146336 | 2 |
| 8497202461586765 | 2 |
| 8155400310837610 | 2 |
In beeline, the number of rows after which header should be repeated is defined by beeline variable headerinterval .
You may set headerinterval using beeline command !set headerinterval 100
Set headerinterval to large value so that possibly you will see header only once.

MYSQL multi JOIN from different tables

I have multiple MYSQLI tables for multiple details and options about a touristic package.
I have package containing the main information, then I have package_option which contains unknown number of options added to the package, and there's package_images which contains the images.
I want to get all the information in one query, but it's prooving a difficult task. Let me explain.
I've used JOIN with but the problem was if the package_option had 3 options and the package_images had 6 images, the result was a 6*4 plus 1 (package) result table.
I would like a result containing all the fields, as many as they originaly are in the tables, not multiplied for each match in every table.
For example, the table I aim for looks like that:
-------------------------------------------------------------------------
| ID | name | description | price | option | image | size | explanation |
-------------------------------------------------------------------------
| 1 | test | some desc | 50 $ | opt. 1 | img1 | 30 | |
| | | | | opt. 2 | img2 | | |
| | | | | opt. 3 | img3 | | |
| | | | | | img4 | | |
| | | | | | img5 | | |
| | | | | | img6 | | |
Right now, the above table gets populated in every field, but it's multiplied, so I don't get only 6 rows, but 24.
I did a lot of JOINS, I'm not a beginer, which is even more frustrating, but it's the first time I try to do that, a select from multiple tables with different columns and unknown number of rows.
package_option and package_images looks like that:
-------------------------------------
| ID | package_id | option / image |
-------------------------------------
| 1 | 1 | opt. 1 / img 1 |
| 2 | 2 | opt. 2 / img 2 |
..... etc
so I don't know how many rows I'll have.
Thank you in advance for t

need assistance in look up the data between 2 tables

I am having 2 tables in Microsoft access.
1st table name - details
2nd table name - code
in 1st table I have more than 15 columns, I need to insert one column after 10th column and rename the heading as "TYPE".
in 2nd table I have 5 column.
Common column in each table is Analysis code.
Table 1
+-------+-------+---------------+------------+---------+
| Test1 | test2 | Analysis code | test4 | test5 |
+-------+-------+---------------+------------+---------+
| ab | dfd | TON | fddafd | 212132 |
| ced | fd | SIN | 2133 | dfd2fd1 |
| ef | fdfd | TON | df2df1d31f | dfd3sa3 |
| gh | dfd | SIN | dfd63 | c22 |
+-------+-------+---------------+------------+---------+
Table 2
+----------+---------------+----------+------------------------+
| sample 1 | Analysis code | sample 3 | Type |
+----------+---------------+----------+------------------------+
| 558825 | TON | a | Terminated on network |
| 258c | SIN | b | International network |
| 5856c | TOF | c | Terminated off network |
| a21c5b | SMS | d | text message |
+----------+---------------+----------+------------------------+
OUT PUT Table
+-------+-------+---------------+-----------------------+------------+---------+
| Test1 | test2 | Analysis code | Type | test4 | test5 |
+-------+-------+---------------+-----------------------+------------+---------+
| ab | dfd | TON | Terminated on network | fddafd | 212132 |
| ced | fd | SIN | International network | 2133 | dfd2fd1 |
| ef | fdfd | TON | Terminated on network | df2df1d31f | dfd3sa3 |
| gh | dfd | SIN | International network | dfd63 | c22 |
+-------+-------+---------------+-----------------------+------------+---------+
You need to join the table1 and Table2 on the corresponding column. In your case "Analysis code"
a sample would be:
SELECT Test1, test2, [table1.Analysis code], table2.type .... rest
FROM table1 left join table2 on table1.[Analysis code] = tble2.[analysis code]
above SQL code will produce [somewhat]your expected output table. Having said that, please allow me to suggest, that you need to read more about SQL language and [relational databases]. will help you more!

Update table from another table throught intermediate table Mysql

I have the next table setup, two tables related by an intermediate table, like this:
Client
| client_id | ...|field_X |
| 1 | ...|value1 |
| 2 | ...|value2 |
| 3 | ...|value3 |
Project
| project_id | ...|field_X |
| 1 | ...| |
| 2 | ...| |
| 3 | ...| |
| 4 | ...| |
| 5 | ...| |
| 6 | ...| |
| 7 | ...| |
client_project
| client_id | project_id|
| 1 | 2 |
| 1 | 3 |
| 2 | 4 |
| 2 | 5 |
| 3 | 6 |
| 3 | 7 |
The field_x in the table project is new and i have to fill it with the data from table client to get approximately something like this:
Project
| project_id | ...|field_X |
| 1 | ...| |
| 2 | ...|value1 |
| 3 | ...|value1 |
| 4 | ...|value2 |
| 5 | ...|value2 |
| 6 | ...|value3 |
| 7 | ...|value3 |
i dont know hot to deal with the intermediate table. i have tried this code but it doesnt work.
INSERT INTO project
(field_x)
(select field_x
from
client_project
inner join
client
where client_project.client_id = client.client_id
);
I have the idea of what i have to do but i am not able to translate it into a sql command because of the intermeditate table.Could someone explain how to deal with it?
Thanks in advance.
I assume you already have all entries in the project table but they're missing the Field_X property? So what you need is an update, not an insert
UPDATE project p, client c, project_client pc SET p.Field_X=c.Field_X WHERE p.ID=pc.ProjectID AND c.ID=pc.ClientID
However, be advised that having the same data in two places is not a good practise; if possible always put one fact in only one place.

How to create View in MySQL to combine rows from second table as CSV colmuns in first

I need to create VIEW in MySQL which can combine two tables in such way that for each row from first table there must be added columns from second table but as row data have to be formatted as multiple filds with multiple CSV for every single row.
My original approach is with MySQL VIEW but I was unable to find the way to show multiple row data from second table as CSV single cell data in view table.
Here are some examples:
1st table: gears
+------------+------------------------+-----------------+
| MainGearID | MainGearName | MainGearType |
+------------+------------------------+-----------------+
| 1 | Main Drive | Spur |
| 2 | Secondary Drive | Spur |
| 3 | Backup Secondary Drive | Hypoid |
| 4 | AUX Drive | Rack and pinion |
+------------+------------------------+-----------------+
2nd table: orbitinggears:
+----------+------------+--------------+--------------+
| OrbitaID | MainGearID | OrbitalType | OrbitalValue |
+----------+------------+--------------+--------------+
| 1 | 1 | Spur | 112 |
| 2 | 1 | Spur | 280 |
| 3 | 2 | Spur | 144 |
| 4 | 2 | Spur | 248 |
| 5 | 3 | Helical | 18 |
| 6 | 4 | Spur | 144 |
+----------+------------+--------------+--------------+
Required View:
+------------+------------------------+-----------------+----------+---------+
| MainGearID | MainGearName | MainGearType | Spur | Helical |
+------------+------------------------+-----------------+----------+---------+
| 1 | Main Drive | Spur | 112,280, | |
| 2 | Secondary Drive | Spur | 144,248, | |
| 3 | Backup Secondary Drive | Hypoid | | 18, |
| 4 | AUX Drive | Rack and pinion | 144, | |
+------------+------------------------+-----------------+----------+---------+
Does anybody have an idea how to create view in this way?
You can use GROUP_CONCAT with IF():
CREATE VIEW v6 AS
SELECT a.MainGearID, a.MainGearName, a.MainGearType,
GROUP_CONCAT(IF(b.OrbitalType='Spur',b.OrbitalValue,null)) AS Spur,
GROUP_CONCAT(IF(b.OrbitalType='Helical',b.OrbitalValue,null)) AS Helical
FROM gears a
JOIN orbitinggears b on b.MainGearID=a.MainGearID
GROUP BY a.MainGearID;