I have a table History with the columns date, person and status and I need to know what is the total amount of time spent since it started until it reaches the finished status ( Finished status can occur multiples times). I need to get the datediff from the first time it’s created until the first time it’s with status
Tag: sql
DB2 leading zeroes [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last month. Improve this question How to trim only zeroes in a leading position in a string? I’m writing a DB2 script that removes all leading zeroes from a string that
How can I indicate the “current” column in an upsert in PostgreSQL?
I have the following upsert with which I have problems because the subqueries give me more than one result. The problem is that I don’t know how to indicate in the upsert to compare the value of the column that is currently being updated. The problem is after the DO UPDATE. Answer I think you are looking for the excluded
How to select the immediate characters BEFORE a specific string in SQL
So imagine I have a SQL tempTable with a text field with 2 pages worth of text in it. pkid text 0 This is an example text with some images names like image1.svg or another one like image2.svg 1 This is another example text image3.svg and several images more like image4 and image5 What I want to know is if
Time difference between start/stop interactions
I have two tables in my database that looks like this learner_lessons learner_lesson_logs Basically, when a user clicks on a video it starts playing and the interaction is recorded as ‘Start’ and a timestamp is created accordingly. Now when a user pauses the video another interaction ‘Pause’ is created and the timestamp is recorded. The user might come back later
SQL want efficient query to SELECT columnA, columnB FROM table1 WHERE both columnA, columnB are in columnC FROM table2 WHERE columndD > value
I’m searching for a more efficient method to accomplish something that I’ve already solved with a few different SQL statements. The problem: I have two tables a transactions table, and an accounts table The transactions table has columns that look like: acct_sending acct_receiving amount tx_datetime 100 101 10 yyyy-mm-dd hh-mm-ss 101 100 5 yyyy-mm-dd hh-mm-ss 101 200 1 yyyy-mm-dd hh-mm-ss
How to pass an SQL function on bulk insert query in node
I have to execute an INSERT INTO query using mysql or mysql2 in node.js The values passed into the query utilizes a spatial geometry function ST_GeomFromGeoJSON() on geoMap column which is of type GEOMETRY. Here is the simplified code: The above code does not work and throws the error Cannot get geometry object from data you send to the GEOMETRY
Insert with Foreign Key Contraints
In the above code, I want to add the distinct values from column make from vehicles into column makeID in makeModel but I get the error INSERT INTO makeModel (makeID) SELECT DISTINCT (make) FROM vehicle Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`dealership`.`makemodel`, CONSTRAINT `makemodel_ibfk_2` FOREIGN KEY (`modelID`) REFERENCES `model` (`ID`)) Answer
Snowflake cross join + lateral flatten
I have a semistructured column that I would like to left lateral join after a cross join. In the above, I would expect the original cross join to expand the result count from 1 to 3; and the left lateral join should not reduce the number of rows returned. The result I obtain is unexpected: COL A SEQ KEY PATH
SQL Query for insert many values in a table and take only a value from another table
I’m looking for insert many values in a table and take the ID refernce from another table. I have tried diffent ways, and finaly I have found this that works. This works, but I’m looking for a “easy query” because I need to write the command from Visual Studio Answer The link I noted earlier should have sufficed to explain