Create a Patern Rank, Based on THE VALUE(s) IN A COLUMN - sql

I have data like this -
I want to create one more column name Pattern and it looks like this -
How to create this column -
It is based on the column 'NAME'. It should Rank Starting from the Row having Parent_ID=(ContentID of the row having Parent ID 1)
It should increase by one and should make the same Group if it get's 'Only For'/'Not For' in the column NAME.
It will work on the group of Jill_Equipment_ID,Req_Group,Operand..
As my complete data in broken into these groups and it will have multiple Jill_Equipment_ID and for each ID multiple Req_Group and for each group multiple Operands.
Please help me in getting it solved. Thanks in advance.

Related

How can I remove Null value from first column but keep the value of the 2nd and thirds columns

I am Omar, a new learner of SQL.
I have a large excel sheet that I want to analyze by SQL.
It has the following columns (Manufacturers, Products, sales)
the problem is, in the first column 'Manufacturers,' the manufacturer name has only been entered once per one manufacturer. while for the rest of the below rows, the cells are empty until the next manufacturer.
Please refer to the attached image for more understanding.
How can I remove these null values in my query results while keeping the values of the product column value?
thank you
The main problem you have is that SQL tables represent unordered sets. So, if you have only your specified columns, you cannot reconstruct the Excel format.
To solve this, you want to load the data into a table that has an identity or auto-incremented column, in order to preserve the insertion order. The exact details depend on the database. Let me call this column id.
Then you can "spread" the value where it is missing. One method is:
select t.*,
max(manufacturer) over (partition by manufacturer_grp) as imputed_manufacturer
from (select t.*,
count(manufacturer) over (order by id) as manufacturer_grp
from t
) t

Sort Order Column Dynamically Created From Another Column (Postgres)

I am trying to output a sort order column on a Postgres select query to give each row an order integer based the values of it's columns - with this sort order derived from another column. Something like this:
select column_1_name, column_2_name, column_3_name, [a formula] AS sort_order
from table_name
The data in the column sort_order_column would be a comma separated list of column names in the order I would like them to show in the sort_order (starting from 1 again for each unique item in the item column).
In the example below, I want to sort the 'car' items first by column_2_name, then by column_3_name. - this means the green car comes before the red car.
For boats, these are sorted first by column_1_name, then column_3_name, then finally by column_2_name. This means the 10m boat comes before the 20m boat.
Data:
Desired output
Thanks in advance.

How can I group a set of similar results and add up values for one final result in SQL?

I know there has to be a simple answer to this question, but I am a total SQL noob. In my result set I have multiple results in one column that have one specific value that is repeated several times. In another column there is another value that needs to be added. Please see the attached photo for clarification.
I want to be able to find all of the values in Column B that correspond to 'A' and add them up for one result like shown. I want to be sure to delete the duplicates in Column A. Any help is greatly appreciated.
You're trying to SUM the values in column B and you're trying to group them by (GROUP BY) the value in column A when you do that. This is accomplished like so:
SELECT
col_a,
SUM(col_b)
FROM
My_Table
GROUP BY
col_a

how to get specific column values in array after sorting any column in datatable

I have html table of 4-5 columns including id, name, description etc...,
I have applied datatable on it. I want to get id column data in an array if I sort name column. How can I get it?
P.s: Sorry for bad english.
I am not sure what programming language you are using. I assume that you want to get that you want the list of id [based on the name sorting]
select id from TABLE order by name
I assume that you are using SQL

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