I have 2 tables: Table 1 (User) contains names of users/leaders and Table 2 (Transactions) contains records of user transactions with a column named “reason” There are several “reasons” which can be …
How to limit the no of results to just 5 per ‘user’ but allow for more rows if the immediate value at 5th row is same as the consecutive rows?
I have a database with Domain_id, salary and salary date of an organisation. My question is i have to find 5 highest salaries per domain, but the no of rows (5 rows) can increase to more, if the …
Minutes between dates when multiple records
Table ‘audit’ has fields id, old_status, new_status, & changed_at. Status contains values Open, On Hold, and Closed. I want to determine how long audit was On Hold, simple calculation: SELECT …
Let SQL throw error then handle or prevent error completely?
In my code I generate a list of IDs then input associated data into a table with ID as the Primary Key. Is it better practice to let SQLSever throw an error and handle it (Integrity Error)? Or should …
Hive Query : To calculate max indicator value based on priority and date
I tried to frame the query but somehow not getting the required result hence posting. I am new to hive. Apologies if it is very simple. Source Data : Ik – priority – ind1 – ind2 – date 1 – A – …
How to select numeric data of certain length
I am trying to select numeric data that is greater than 5 bytes. I have entered the below but get an error of ERROR: Function LENGTH requires a character expression as argument 1. Not sure what I am …
How to convert “3 Days 18 Hours 39 Minutes” into seconds in SQL Server?
How to convert “3 Days 18 Hours 39 Minutes” into seconds in SQL Server?
Select dummy values if where clause returns zero rows
I am using SQL Server 2016. I have a SQL and it has where clause which returns zero or non-zero rows depending on data present in the table at a specific time. For example the SQL is: select step_id, …
Scale CASE WHEN to retrieve non-holiday dates
I have table containing records with start and end dates, so I have to grab every record that started on a Friday, and if any Friday is a holiday, get Thursday, and if Friday and Thursday are holidays,…
count(distinct) over (partition by… doesn’t work in Oracle SQL
I want to count the distinct day_number over the past 30 days. However, the distinct function can’t be used with over If I delete distinct, it will give me the total count of the day_number, but …