my code stock.com

blabla

Snippet options

Download: Download snippet as teste-sql.sql.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

SELECT "W (n-3)", "W (n-2)", "W (n-1)", "W (n)" FROM ( 
  SELECT 1 IND,
    MAX ( DECODE(SEMANA,:WK-3,  a.MAX )) "W (n-3)",
    MAX ( DECODE(SEMANA,:WK-2,  a.MAX )) "W (n-2)",
    MAX ( DECODE(SEMANA,:WK-1,  a.MAX )) "W (n-1)",
    MAX ( DECODE(SEMANA,:WK,  a.MAX )) "W (n)"
  FROM V_PERF_VPP_V2 a
  WHERE a.ANO = :ANO
   AND a.SEMANA BETWEEN :WK-3 AND :WK
   AND a.TIPO = 'SEMANA'
  UNION
  SELECT 2 IND,
    MIN ( DECODE(SEMANA,:WK-3,  a.MIN )) "W (n-3)",
    MIN ( DECODE(SEMANA,:WK-2,  a.MIN )) "W (n-2)",
    MIN ( DECODE(SEMANA,:WK-1,  a.MIN )) "W (n-1)",
    MIN ( DECODE(SEMANA,:WK,  a.MIN )) "W (n)"
  FROM V_PERF_VPP_V2 a
  WHERE a.ANO = :ANO
   AND a.SEMANA BETWEEN :WK-3 AND :WK
   AND a.TIPO = 'SEMANA'
  UNION
  SELECT 3 IND,
    SUM ( DECODE(SEMANA,:WK-3,  a.TOTAL )) "W (n-3)",
    SUM ( DECODE(SEMANA,:WK-2,  a.TOTAL )) "W (n-2)",
    SUM ( DECODE(SEMANA,:WK-1,  a.TOTAL )) "W (n-1)",
    SUM ( DECODE(SEMANA,:WK,  a.TOTAL )) "W (n)"
  FROM V_PERF_VPP_V2 a
  WHERE a.ANO = :ANO
   AND a.SEMANA BETWEEN :WK-3 AND :WK
   AND a.TIPO = 'SEMANA'
) ORDER BY IND

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.