in Education by
I have a table with the following structure: yyyymm Revenue ... ... 201701 450 201701 600 201702 350 ... ... 201903 559 I want a query that returns in the following form: yyyymm TTM Revenue 201701 Sum of Revenue from 201601 to 201612 201702 Sum of Revenue from 201602 to 201701 ... ... I tried to use: select yyyymm, sum(case when ...) from table group by 1 But I'm unable to figure out the logic and syntax. Can someone help me with this please? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I don't know if this will help you any or not, but this would be the approach for Microsoft Sql Server, minus the 12 month part of the equation, which would be a little bit of work in T-Sql if the date is stored in this format to cast it as a date and run a where over that date. CREATE TABLE #temp (yyyymm int, revenue int) INSERT INTO #temp ( yyyymm, revenue ) VALUES (201701, 450), (201701, 600), (201702,350) SELECT yyyymm, SUM(revenue) From #temp GROUP BY #temp.yyyymm DROP TABLE #temp

Related questions

0 votes
    I have a table with the following structure: yyyymm Revenue ... ... 201701 450 201701 600 201702 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I am using REPLACE in an SQL view to remove the spaces from a property number. The function is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    SELECT id, amount FROM report I need amount to be amount if report.type='P' and -amount if report.type='N' ... this to the above query? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I would like to ask for performance of SQL. This is my query: Select A.code ,A.name ,(Select B. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have a table in Db2 called myTable. It has several columns: a | b | date1 | date2 ----- ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have a table in Db2 called myTable. It has several columns: a | b | date1 | date2 ----- ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have a table in Db2 called myTable. It has several columns: a | b | date1 | date2 ----- ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    I am trying to format of years and months in a manner like yy-mm I can calculate like this to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I have an access table that has in one column a list of groups and then another column that has a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am trying to format of years and months in a manner like yy-mm I can calculate like this to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    I have an access table that has in one column a list of groups and then another column that has a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    I am trying to format of years and months in a manner like yy-mm I can calculate like this to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I am trying to format of years and months in a manner like yy-mm I can calculate like this to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I need to give rank to records based on follows Based on b_id and priority combination need to rank ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Get all Users from first table that have any word matching in another table; I have Users table that ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
...