I have the following query logic Show comments which is not deleted Show comments which is deleted after created, within a timespan of 30 days before today(Today – Createddate <= 30) Below is the logic which I wrote, but I don’t think it is working correct. Answer
How to sum the amount and merge the offers in a single row?
I have table with discount transactions data as below: TransactionID DiscountAmount DiscountOffer S011-T012 50 Jun-21 S011-T012 25 ManagerDisc S011-T025 15 Jul-21 I need to create a table in a way that for a single transaction, Discount amount is summed up and Discount offer is shown side-by-side (maybe with …
How add select in list without join
I don’t need to join in a whole table, but just want a value from the table returned in my select list (but other tables are joined for other items). It’s giving me an error…incorrect syntax near select I’m having trouble searching online for this. Answer Assuming the scalar subquery r…
Mysql query : how to calculate statistic growth rate between two period per category
From this table of dates and categories inputs : I’d like to get these folowing table, showing number of rows per category for each first and second quarter, and the growth of number of rows between second and first quarter, in value, and in percentage – which is a simple statistic table type that…
Sql query for finding specific records from the table based on hierarchy
I am trying to make a SQL Query. So There are 3 sections available,Method 1,2 and 3. If A Group+SG Combination is found anywhere, we take that value based on the following hierarchy: Method3>Method2>Method1. Finally, In the output, we have That particular as Final Group and Final SG, And the value is pi…
how many banks are currently rated B+ or above and when was the last time (dateindex) that they had been below
I have these two tables and im trying to get the dateindex of the last time that the company was rated below a B+. dateindex=19941 which means 1994 quarter 1 This selects all the companies that have B+ or above in q2 2020 And it yields the following How can I add the dateindex the last time it was below
SQL: Return Aggregated Results based on some conditions
I need help with making a conclusion in SQL Server based on some column’s values, like status aggregation sort of. As an example, below is a table containing server tasks and their status. If I want to return the aggregated status of each server here are the rules: if all the server tasks are at status …
How to create a complex aggregate function in sqlite
Suppose I have the following table where there are two sets of observation dates (2015-01-01, 2016-01-01) in the first column. For each observation date, there are associated item_date and item_value. observation_date item_date item_value 2015-01-01 2012-12-31 0 2015-01-01 2013-03-31 1 2015-01-01 2013-06-30 2…
Return false if no rows for select
I have next query: It works fine, if we have some records in new_date table, but if it is empty for some user, query just returns empty string. How I can return false, if there are no records also? Answer You could just selects an EXISTS expression here: This would always return just a single record, containi…
what are the alternative approaches to optimize this sql query?
I am just a beginner in sql and i am trying to optimize sql query but couldn’t get any idea yet, so i am sharing the query with you guys if anybody help me out through this will be very appreciated. Tables are already indexed but if you have any composite indexing approach or anything you can share it. …