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…
Error starting Tomcat context.Exception: org.springframework.beans.factory.BeanCreationException.Message:Error creating bean with name ‘h2Console’ def
I have this simple CRUD Spring HTTP Service (see ). I would like to achieve something like . I made use of Thymeleaf and 2 html files: add-edit-employee.html and list-employees.html. Initial data comes from an sql table: data.sql & schema.sql. When I run the project I get error: Log of the errors 2 Pom fi…
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…
Snowflake how to split a field having values separated with commas and add them separately to the target table each value in a single row?
I have a field that might hold values as follows: field_val = ‘Val1, Val2’; So using merge into command, I need to split these values and add them separately each as a single row. In that case, I don’t want them added row to be: 23, ‘Val1, Val2’ What I want is to add the separate…
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.…
To convert the WHILE loop query into FOR loop query
This is the table created and inserted values into it in SQL server And using WHILE loop, I achieved the below query in SQL Server. Now I want the same above result with the usage of FOR loop, I know in SQL server FOR loop is not used, but with WHILE loop we can simulate the FOR loop in SQL
Spring Data Jpa to get data which doesn’t have entity representation
I’m trying to find the best way to map my data on ORM. I have a query which gets me data from MySQL database which look like What would be the most optimal way to get these data with Spring boot and Spring data?? Should I use @Query annotation and execute this or somehow create entities for Equipment an…
MySQL: Create table from select with engine different from source table
I would like to copy an existing table data to a new table with a different engine: CREATE TABLE `t_backup` (SELECT * FROM `t`) ENGINE=MyIsam; But it prompts syntax error. I know I can write the …