Skip to content

Tag: sql

Window functions + self join to solve?

I want to display how many days an item was in each stage. We have many items, so just showing one ID for now for simplicity. For first stage it should be action_date -created time. For last stage it …

Read table[columns] and display in console

I have one table and about 20 columns which contain more than 5000 rows. Right now I want to display all 20 columns in console, and I came to thirth column and I get error Here is my code: This peace of code make me error When I change this to Anyone can guide me and tell me what’s wrong

how to use NULLIF with aggregate function

I’m using SQL Management Studio 2012. I’m getting a ‘Divide by zero error encountered’ error. I’m aware this requires the use of NULLIF but I’m unsure how to use it in my query. This is my query I’ve actually asked this question before which some kind person answered …

SQL QUERY TO SHOW FIRST IN AND FIRST OUT

my query like this : output getting : BUT I NEED TO SHOW THE RESULT LIKE THIS Answer Assuming that your in and outs are interleaved, you can use row_number() and aggregation: For your particular query, this is a little simpler:

SQL Server Lag and Lead

I’m using SQL Server 2014. I have a table: I have some data: If I perform a LAG and LEAD using the below for one Job, I get the desired result: Result: Notice the NULL for the first FromActionCode and LastToCode, which is correct. However, If I look at all records, it messes it up: What am I missing? An…