Skip to content

Displaying the difference between rows in the same table

I have a table named Employee_audit with following schema, emp_audit_id eid name salary 1 1 Daniel 1000 2 1 Dani 1000 3 1 Danny 3000 My goal is to write a SQL query which will return in following format, considering the first row also as changed value from null. columnName oldValue newValue name null Daniel s…

Select data using closest date

I have two tables like below: table1 table2 I have to calculate TotalPrice (price x Quantity) from each ID for the date ‘2017-07-28’ but condition is that: if no price is available for a given date, the price closest to but before the date should be used. I have tried the below query but its not g…

Single quotes cause trouble while filtering in Slick

I have statements such as below and they fail with exceptions such as this I have tried to escape the single quote but wasn’t successful. When I tried to insert a record such as this: The exception I’ve gotten is: Please note that I am using H2 in Mysql mode to run my tests. Answer That error sugg…

SQL Server filling gaps in time series

I’m having trouble with a request in SQL. I have two tables, one representing a vector of dates and another timeseries of prices for different securities: Dates: DateId Date 1 2021-01-01 2 2021-01-02 3 2021-01-03 TimeSerie: SecurityId DateId Value 1 1 0.25 1 3 0.32 2 1 0.41 2 2 0.67 The timeserie may ha…

How to get the sum of values in a table interval?

The question is very simple :-). I’m a beginner. tables Result: A task….. There are two date variables. How to get the sum of values(qty) between dates(@startDate – @endDate). How to get the sum of values(qty) up to @startDate. How get the sum of values(qty) down to @endDate. If DocumentType is 1.…