HIVE :- Read latest row if all coloumns matches - sql

I need to select rows if all the column value matches and take the latest one assume that others are duplicate to it . but if any one column data not matched with the other row I need to show both the rows.
ex
My table sample data may look like below
My expected result is
I tried to get the max of it and I am getting only one row instant three rows per name.
My actual table contains 40 columns and I gave only the sample data and expected result for understanding

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

SQL Table Transformation Course on Code Academy

This question is from the SQL table transformation course from Code Academy. I am curious to know the difference between the following 2 queries and why the result set showed different answers:
The issue here is that airports.code may have duplicates. In this case, joining from the flights to airports table could result in duplicated rows, as a record from flights could match multiple records in airports.
If the field airports.code were distinct, i.e. there were no duplicates in that column, then both queries would have returned the same number of results. Consider the following sample data:
flights:
origin
1
2
3
airports:
code
1
1
2
3
It should be clear that the WHERE IN query (the first one) would return only three records, one for each origin value. But the second query with the join would actually return four records, since origin=1 would match twice to code=1.

HIVE table - Get records which are closest to a given numeric value

From a hive table, I want records which are closest to a given value of each of the columns.
E.g.
The table has columns - total_score, avg_score, etc. I want to get records which have total_score and avg_score close or equal to "a given value".
Note - Table has approx. 183 million rows and I want 1,50,000 records which are closest/equal to the given value of each of the columns.
Please help me with the process of doing it.
The general concept needs to be top x, ordered by the absolute value of difference between parameter value and values in list.

Get fields from one column to another in Access

Below i have a table where i need to get fields from one column to three columns.
This is how i would like the data to end up
Column1
Music
Column2
com.sec.android.app.music
Column3
com.sec.android.app.music.MusicActionTabActivity
Give the table a numeric autonumber id
Remove the rows with no data with a select where blank spaces or null
Find records with no point in the content with a select
Use the previous query as a source and use the id to find the id + 1 to find the next record and do the same with + 2 to find the second row
Build a table to hold the new structure and use the query as a source to insert the new created data in the new table with the 3 columns structure.
This is an example using sql server
Test table design
Data in table
Query
Look at the query from the inside. The first query inside clean the null records. Then the second query find the records with out point. This records are the reference to find the related two records. Then the id of the records with out point are used to make a query in the select adding 1 for the next record and then other query adding 2 to find the other record. Now you only need to create a table to insert this data, using this query as the source.

how to find index of a row in sql server?

How can i fetch column names from a table on index basis, like I want to make a tables whose column name should be the name of last column fields of a result set of a query, but those result sets last columns value may be different at different execution time, so i want to know how can i fetch those index value of that last column to make a temp table with column name of those last columns value of a result set.
Is there any way/function in sql server to dynamically form that?
sp_helpindex:
Reports information about the indexes
on a table or view.
You can also use ROW_NUMBER as explained here