In the table below, there are job activities and unique identifiers under lodnum. I’m trying to figure out a way to get the time difference in between a job. A job such as pallet move has two entries. …
Tag: sql
psycopg2: cursor.execute storing only table structure, no data
I am trying to store some tables I create in my code in an RDS instance using psycopg2. The script runs without issue and I can see the table being stored correctly in the DB. However, if I try to retrieve the query, I only see the columns, but no data: This script runs without issues and, printing out file_c…
LAST_VALUE function causing error: “Invalid in the select list…” SQL
I need to pull the most recent value for a given field as dictated by entry date. When I try to use LAST_VALUE function, I get the following error message “An Error occurred while executing the …
SQL Subtract from different tables
I’m subtracting values from diferent tables based on ID. Its like an inventory where I’ve the tables for Itens In and Itens Out. What I want to do is to substract the Itens In – Itens Out based on ID …
How to findout a number between two column in SQL Server 2008
Suppose I have table called dbo.tbl_Search Id From To ——————- 1 200 210 2 212 220 3 203 215 4 225 240 Suppose, I search for No.-205 then I would to …
MySQL DATEDIFF function VS compare INTERVAL DAY
What is the difference between DATEDIFF function and subtract INTERVAL DAY directly? SELECT * FROM table WHERE DATEDIFF(CURDATE(), publish_date) = …
Oracle | Update Long type | Error: Illegal use of LONG datatype
How to rectify issue on UPDATE? Following is related data and error Following is table structure: Not able to find answers in related questions. Not sure whether i need to modify table datatype but when i try to modify it says remove data first. Answer if ID is Primary Key – it should not be LONG. The L…
Is there an alternative to WHERE COUNT () with Window Function in PostgreSQL?
I’m trying to do a grouping by two columns and filter the result only by records that don’t have the first column duplicated. Then the result values could be used as KEY and VALUE, respectively. I achieved the desired result in two different ways, but none of them seems to be adequate. To simplify…
Looping in SQL with TempTable
I am new to SQL Server, can you please help me to write query for my scenario? I have this Table1 : Input to my stored procedure is a PolicyNumber e.g 1234 and the code should return 5 rows. I need to cover these cases: If the first payment is not cancelled, I need return that row. If the first
Pivoting Days/Hours in SQL Server From Header to Row Level
I have a list of hours that are under headings from and to. I need to Pivot those to be by days with from and to headings. I’ve tried unpivoting in Excel and Pivot in SQL Server, nothing is working. …