Sqlserver
 sql >> डेटाबेस >  >> RDS >> Sqlserver

मूल्यों की पूर्ण अनुक्रमिक श्रेणी का उत्पादन

संपादित करें नई जानकारी के लिए

;WITH d AS ( SELECT TAT = CASE WHEN TAT > 191 THEN 192 ELSE TAT END,
   SUM(CASE WHEN [Month Entered] = 1  THEN 1 ELSE 0 END) AS JAN,
   SUM(CASE WHEN [Month Entered] = 2  THEN 1 ELSE 0 END) AS FEB,
   SUM(CASE WHEN [Month Entered] = 3  THEN 1 ELSE 0 END) AS MAR,
   SUM(CASE WHEN [Month Entered] = 4  THEN 1 ELSE 0 END) AS APR,
   SUM(CASE WHEN [Month Entered] = 5  THEN 1 ELSE 0 END) AS MAY,
   SUM(CASE WHEN [Month Entered] = 6  THEN 1 ELSE 0 END) AS JUN,
   SUM(CASE WHEN [Month Entered] = 7  THEN 1 ELSE 0 END) AS JUL,
   SUM(CASE WHEN [Month Entered] = 8  THEN 1 ELSE 0 END) AS AUG,
   SUM(CASE WHEN [Month Entered] = 9  THEN 1 ELSE 0 END) AS SEP,
   SUM(CASE WHEN [Month Entered] = 10 THEN 1 ELSE 0 END) AS OCT,
   SUM(CASE WHEN [Month Entered] = 11 THEN 1 ELSE 0 END) AS NOV,
   SUM(CASE WHEN [Month Entered] = 12 THEN 1 ELSE 0 END) AS DEC
  FROM [SalesDWH].[dbo].[TurnAround]
  WHERE [datetime entered] >= '20100101'
    AND [datetime entered] <  '20110101'
  GROUP BY CASE WHEN TAT > 191 THEN 192 ELSE TAT END
),
n AS ( SELECT TOP (193) n = ROW_NUMBER() OVER (ORDER BY [object_id]) - 1
  FROM sys.all_columns ORDER BY [object_id]
)
SELECT TAT = n.n,
  JAN = COALESCE(RTRIM(NULLIF(JAN, 0)), ''),
  FEB = COALESCE(RTRIM(NULLIF(FEB, 0)), ''),
  MAR = COALESCE(RTRIM(NULLIF(MAR, 0)), ''),
  APR = COALESCE(RTRIM(NULLIF(APR, 0)), ''),
  MAY = COALESCE(RTRIM(NULLIF(MAY, 0)), ''),
  JUN = COALESCE(RTRIM(NULLIF(JUN, 0)), ''),
  JUL = COALESCE(RTRIM(NULLIF(JUL, 0)), ''),
  AUG = COALESCE(RTRIM(NULLIF(AUG, 0)), ''),
  SEP = COALESCE(RTRIM(NULLIF(SEP, 0)), ''),
  OCT = COALESCE(RTRIM(NULLIF(OCT, 0)), ''),
  NOV = COALESCE(RTRIM(NULLIF(NOV, 0)), ''),
  DEC = COALESCE(RTRIM(NULLIF(DEC, 0)), '')
FROM n LEFT OUTER JOIN d ON n.n = d.TAT 
ORDER BY n.n; -- do not use ordinal numbers for ORDER BY!


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. वर्णों की तालिका से पुनरावर्ती प्रतिस्थापन

  2. सभी 0 मानों को NULL . पर सेट करें

  3. पैरामीटर के रूप में तालिका नाम के साथ संग्रहीत प्रक्रिया

  4. स्पॉटलाइट क्लाउड अलार्म कस्टमाइज़ करें

  5. डेटाटाइम कॉलम को वर्ष, महीने और सप्ताह में विभाजित करना