Return lines from a table where a value in one column is larger than the next but the corresponding value in a adjacent column is smaller - sql

I have this data:
It's ordered ascendingly by the left hand column. I'd like a query that says if the timestamp in the right-hand column is before the timestamp of the preceding row, to return that row.
TIA

Related

SQL - Assign row numbers based on whether other rows in the result have a column value same as the current row, if yes assign same row number to them

I want to assign row number/ rank dynamically to record while selecting, so that all the items from a particular HOTEL is allotted same row number if Meal is included in any of it's TYPE, else all will have cumulative/ subsequent row value/ rank from the previous one. Here's how my table looks
and this is how it needs to be with the row numbers
.
I tried using ROW_NUMBER() and DENSE_RANK() over HOTEL but they seem to be assigning same row number for records having same HOTEL but not having Meal included in it's TYPE.

Is there any way to sum a column in rdlc by matching previous column?

Is there any way to sum a column in rdlc by matching previous column? Let say I have a Code_No column and the Value of this column may be duplicate. I want to sum its left column only if the value of this Code_No column are different.

Return the row includes the maximum value of specific column if two rows have the same values.

I have a result from the SQL query, wich is displayed below,
I want to build a SQL query, which can return the row includes maximum number from the last column if any two rows (or more than 2) have the same number from the first column.
For instance, from the table, you can see the top two rows have the same number from the first column, which is 2195333. If the SQL query runs, it will return the first row and the rest of rows, discarding the 2nd row only, since the last column for the 2nd row is 1, which is smaller than 2 from the 1st row.
I was thinking about using the while loop in SQL, like run the loop from the 1st row to the last row, if there are any rows have the same value from the first column, it will return the row which has the maximum value from the last column. Since I am new to SQL, I have no idea how to implement it. Please me help me. Thanks
The question, sample data, and desired results are lacking a bit.
But if I understand your question, you can use the WITH TIES clause in concert with Row_Number()
Example
Select Top 1 with ties *
From YourTable
Order By Row_Number() over (Partition By YourCol1 Order By YourLastCol Desc)
Edit Use Dense_Rank() if you want to see ties

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?

Find first of a set of related records, dependent on a value in another row

I have a table in which a row represents a subsection of a larger block of data.
Given an input parameter which identifies one of these rows, I would like to return a different row which represents the root record.
Specifically I would like to retrieve the first record in this set.
For example:
Find the row with column X value of Y.
Get the value A, of column Z.
Return the first row with column Z value of A.
What is the best way of doing this?
Two separate queries on the original table?
A single query on the original table?
Construct a new view that would enable a single query?
Something else?
You can get the same row, if you will not order you rows by some column, but general answer will be
select top 1 *
from table
where Z = (select Z from table where X = #parameter)
order by ???