Sunday, 31 May 2015

SQL Server Important and common interview queries

Question 1:Write a query which will produce the below output ?











Solution - We can achieve the above situation by the following ways -

Query 1
Select 
  T0.ID 
 ,T0.Num
,(Select SUM(Num) from #Temp T1 where T1.Id<=T0.ID) as Result
From #temp T0
Query 2
Select
T0.ID
,T0.Num
,SUM(T1.Num) as Result
from #Temp T0 
Inner Join #Temp T1 on T1.Id<=T0.Id
Group by T0.ID ,T0.Num

1 comment:

  1. Data Warehouse - OLAP Servers
    As we know about that data in a data warehouse is organized to support analysis rather than to process real-time transactions as in online transaction processing systems (OLTP). OLAP technology enables data warehouses to be used effectively for online analysis, providing rapid responses to iterative complex analytical queries.
    Data Warehouse - OLAP Servers

    ReplyDelete