Make duplicate records in a table in hive - hive

I have a requirement of making the duplicate records in a table from the number specified in a separate table. Given below the example.
Table A1 having many columns along with seg_id column. And Table B1 having many columns along with seg_id column and iteration_no column.
I have to join both the tables using seg_id column and take the value present in iteration_no column. If the value is 5 then I need to duplicate the entire seg_id row in Table A1 into 5 rows without any changes. Could you please help.

Related

How to reorganise a table basis a criteria

I have a table where columns exist at different rows as shown in Problem figure.
I am able to identify the rows of column headers (Numbered 1 in column A) and there values(Numbered 2,3 onwards in Column A).
I want collate it in a neat table as shown in Solution table; where all Column headers are in one row and subsequently we have their values.
Problem and expected results are as shown in picture

How to map (relate) two unrelated tables without adding any column in sql and powerbi

I have 2 tables named A1 and B1. And both the tables has commonly 3 columns but in different variable. Considering A1 as the master table I have to map B1 but the values in A1 (those particular ID's(3 columns)) will not be present in B1 and vice versa. And the ID's present in both table contains duplicates. I have to find the relationship (map) the two tables without adding any extra attribute in SQL and POWERBI
Here is the sample table:
Copy the ID from A1 table to a new table. (Use 'Add as new query' option)
Merge the ID from B1 table to the new column you just created.
Right click and remove duplicates from the new column. Now you have a master ID column without any duplicate values.
Map this column with ID in A1 and B1.

Adding auto-incremenation on a VARCHAR column on an SQL Server table

I need to alter customer_number column in organisation table so, that it would become auto-incrementable.
As in, when adding rows to the table, this certain column would get bigger number each time. It is not the id column.
Example: If there would be no rows or only rows that have no value on customer_number column, the newly added organisation row would get 1 as the value for its customer_number column. If there would be already for example two rows with values on said column - say 100 and 200 - the new row would get value 201 on that column.
Is that even possible to do by altering an existing table and column?

SQL query to update one for one

I have table A with one to many relationship to table B. Whenever I do an update I create new record in table A with a new batch of records related created in table B. I had a bug in my code so when new items where being created the order of them was being reversed. I need to write a SQL query to update items in table B related to second item in table A to be the same as the ones related to first item in table A. I hope it makes any sense, will try to illustrate:
A1 -> B - 1234
A2 -> B - 4321
I want to update second set of values from table B to be the same as the ones related to A1 (1234)
You should not think of records order in database table. The only way to specify order of rows is ORDER BY clause in SELECT statement.
Make row_order or idx column in table B and put there required value for each item.
In some cases you will also get different order of B items for the first/source A record when selecting them without specifying order in ORDER BY clause.
Relational database table has no notion about neither row order nor column order.

Select single row from database table with one field different and all other being same

I have a database table with 8 fields say Table(a,b,c,d,e,f,g,h).For some rows one of the field is different(say 4 different a values) while all other field values(b-h) in the schema are same.I have to make a table selecting just one rows from such rows with different a's but same b-h.That is I can select any one of the different a's and keep b-h same which they are and display it in table as 1 single row instead of 4.
SELECT MIN(a) a,b,c,d,e,f,g,h
FROM mytable
GROUP BY b,c,d,e,f,g,h