I have to query in sql server where I have to find for each id it’s volume such that we have last 1 year date for each id with it’s volume. for example below is my data , for each id I need to query the last 1 year transaction from when we have the entry for that id as
Tag: sql
TSQL filter that I do not understand, 2 versions that I thought would return the same data do not
So I have a SQL statement that was not returning data like it should (MSSQL Server), in part of the query I had this turns out if I changed that to then it returned the data I expected, I would have thought those 2 things would be equivalent but obviously not in TSQL. Here is the full Statement My question
check if value is available in DB or not
I have a table which has the schema: i need a query for the report which contains whether the name i give exists in the DB . the name AD,BC,CA should be given by me and its not in any other table. Thanks in advance Answer Use an outer join against a values list:
How to convert MM/YYYY/DD format string to DATE in SQL Server?
I have a column for which I need to convert the data to DATE format. I receive below error whenever I encounter the data ‘MM/YYYY/DD’ format, but it works fine for other formats. Conversion failed when converting date and/or time from character string Sample data: SELECT ISDATE(’05/2020/29&#…
SQL Server transform xml and parse single values but not with build-in functions
I am trying to parse and transform XML values in SQL Server 2016. I can not use the the sp_xml_preparedocument or sp_xml_removedocument built-in procedures because I want to have it in a table value function. I would like to select these 4 values: testXML…821327282 Test value Test attribute Test propert…
How to join queries with a subquery?
So I’m a total newbie trying to solve this exercise where I have to find all the dishes that are marked as Vegetarian but contain Turkey meat in their ingredients. This is what I’ve tried (this is where I inner join 3 tables to find the ingredients): this is where I can’t seem to be able to …
SQL query with dynamic parameters
I tried to get some data from DB. I need get account information from my table – this type of information will depend on User. If he/she will insert account type = 1 -> he will get this information. How could I create query if it will depend on user: for example user could choose one or more account …
FOR loop in Oracle SQL or Apply SQL to multiple Oracle tables
My SQL is a bit rusty, so I don’t know whether the following is even possible: I have multiple tables t_a, t_b, t_c with the same column layout and I want to apply the same operation to them, namely output some aggregation into another table. For a table t_x this would look like this: I now want to exec…
How to use CASE WHEN in PostgreSQL without adding values to aggregation and GROUP BY?
I need to take one timestamp if my condition is right and other value, if not. I made such condition: CASE WHEN tr.type = ‘deposit’ THEN tr.timestamp::date ELSE tr.status_last_change_timestamp::date …
How to delete records of orders that is canceled within 5 minutes in database?
I have a record of users’ purchasing behavior. However, it is long and includes a lot of redundant data. I want to delete orders that purchased and deleted within 5 min My query so far: –TABLE 3 COD …