Skip to content
Advertisement

Tag: window-functions

Getting values based on other column

I have the following data in SQL. Is there a way using SELECT QUERY that we can replace the NULL values in DATE column based on the REF values? Like replace the NULL values with the first available date for matching REF value, without making any change to the database. Expected Result Answer You can do it with MAX() window

Find two values of one Column based on value of another column per ID

I have a sqlite db with one table that called Loan. This table with sample data is here: Loan Table at sqlfiddle.com This table contains below Columns: Now, I need a query to show desired result, contain [empid],[Codepayid],[Lval-1],[Lval-2],[Sum(Lint)],[Lrmn-1],[Lrmn-2], With this Conditions: For example: Result: EmpID CodepayID Lval1 Lval2 Sum(Lint) Lrmn1 Lrmn2 12450400 649 405480 405485 270320 337900 202740 Answer Use

Display total where row number is max row_number

I have a query that displays invoice information, and in final column displays the Supplier’s total balance, I only want the total to be displayed on the last line of that supplier’s invoice entries. ie. the results may contain 100 invoices for say 20 suppliers, each supplier having a different number of invoices, the Account_Total should only be displayed on

Using SQL, when there are multiple columns with dates. how can I determine and return a row where the date is between the other rows?

I am building a table for a data warehouse that needs to have a row for each change that occurs. The issue is that there are sometimes changes that occur in the subgroups and I can’t figure out how to show those changes. For example, I have the following table: RowNumber Code CorrectedProductYear ProductYear Product CategoryYear Category PartYear Parts KeepRow

SQL to find records with last 3 same status

I have the following tasks table: I need to run a query that returns only the types which their last 3 tasks finished with status “FAILED”. How can I do this? Should I use a window function? Thanks Answer You can use aggregation and filtering after using row_number() to get the last three rows: Actually, a slightly simpler method is:

Why does Hive throw me an error while using Order by date?

I am trying to write a query In hive and I am seeing the following error. “Error while compiling statement: FAILED: SemanticException Failed to breakup Windowing invocations into Groups. At least 1 group must only depend on input columns. Also check for circular dependencies. Underlying error: Primitve type DATE not supported in Value Boundary expression. I used the same query

Advertisement