Get Up to 40% OFF New-Season StylesMenWomen * Limited time only.

SQL Interview Questions Intermediate level

Que. Get me segment, year wise total sale, avg sale ,
Output should be like

Ans.

select     
       Segment
  ,sum(sales) as segment_Total_sales
  ,AVG(sales) as segment_Avg_sales
  , YEAR([Order Date]) as year
 
from  [DB1].[dbo].[Superstore]
group by  Segment,
      YEAR([Order Date])

Trainingya Rating On this Answer: 10/10

Que. Get me segment, year wise total sale, avg yearly sale per segment
Output should be like


Divide total sale by 4 as there are four years 2013,14,15 and 16 in the data

Ans.

select 
      
       Segment
  ,sum(sales)/4 as segment_Total_sales
from  [DB1].[dbo].[Superstore]
group by  Segment

Trainingya Rating On this Answer: 10/10

Que. Get all those customer who have at least 3 orders
ans – 743 customers
Output should be like

Ans.

select 
      
      [Customer Name],  
  [Customer ID]
, COUNT (distinct  ([Order ID])) as total_order_count
from  [DB1].[dbo].[Superstore]
group by      [Customer Name],  
  [Customer ID]
  having COUNT (distinct  ([Order ID]))>2

Trainingya Rating On this Answer: 10/10

Que. Get all those customer who have give all the orders from same state
ans : 15 customers
Output should be like

Ans.

select 
      
      [Customer Name],  
  [Customer ID]
, COUNT (distinct  (State)) as total_state_count
from  [DB1].[dbo].[Superstore]
group by      [Customer Name],  
  [Customer ID]
  having COUNT (distinct  (State))=1

Trainingya Rating On this Answer: 10/10

Chat with Counsellor