Calculating CTC Ratios by Job Family: A Comparative Analysis of India and International Markets

Calculating CTC Ratios by Job Family: A Comparative Analysis of India and International Markets

Introduction

The problem at hand involves analyzing a dataset containing information about salaries (CTC) in various job families across different countries. The goal is to calculate the ratio of CTC for each job family internationally compared to India. This analysis requires a deep understanding of SQL aggregation, window functions, and data partitioning.

In this article, we will explore the steps involved in solving this problem using SQL Server. We’ll delve into the world of window functions, aggregations, and subqueries to extract valuable insights from our dataset.

Understanding the Problem

Let’s first examine the provided dataset:

ctcjob_familycountrycity
12000serviceindiadelhi
15000managementaustraliamelbourne
16000it executiveindiadelhi
16000serviceindiajaipur
14000managementaustraliasydney
10000BillingcanadaToronto
20000Billingcanadamontreal
15000servicecanadatoronto
18000Billingindiapune
22000it executiveindiapune
20000Billingindiamumbai
12000managementindiadelhi
14000managementindianoida
19000managementcanadatoronto
19000managementcanadamontreal

We want to calculate the ratio of CTC for each job family internationally compared to India. For example, we can see that the total CTC for Billing in Canada is $30,000, while the total CTC for Billing in India is $38,000. Therefore, the ratio of CTC for Billing in Canada compared to India is 0.78.

Solution Overview

To solve this problem, we’ll employ a combination of SQL aggregation and window functions. The approach involves:

  1. Using aggregations to calculate the total CTC for each job family across all countries.
  2. Applying window functions to partition the data by job family and country, allowing us to compare the CTC values within each group.
  3. Using subqueries or join operations to filter out the data for India if required.

Step 1: Calculating Total CTC for Each Job Family

To start, we need to calculate the total CTC for each job family across all countries. We can use aggregations to achieve this:

SELECT 
    job_family,
    SUM(ctc) AS total_ctc
FROM 
    t
GROUP BY 
    job_family;

This query returns a table with the total CTC for each job family, allowing us to compare these values internationally.

Step 2: Applying Window Functions

Next, we’ll use window functions to partition the data by job family and country. This will enable us to calculate the ratio of CTC for each job family compared to India:

SELECT 
    job_family,
    country,
    SUM(ctc) * 1.0 / SUM(CASE WHEN country = 'India' THEN ctc END) OVER (PARTITION BY job_family) AS ratio
FROM 
    t
GROUP BY 
    job_family, country;

In this query:

  • We use the SUM aggregation function to calculate the total CTC for each job family.
  • We apply the window function SUM(CASE WHEN country = 'India' THEN ctc END) to partition the data by job family. This function returns 0 for all rows where the country is not India and the total CTC value for those rows.
  • We use the OVER clause to specify the partitioning criteria, which in this case is the job_family column.

This query will return a table with the ratio of CTC for each job family compared to India.

Step 3: Filtering Out Data for India (Optional)

If required, we can filter out the data for India by using a subquery or join operation:

SELECT 
    job_family,
    country,
    SUM(ctc) * 1.0 / SUM(CASE WHEN country = 'India' THEN ctc END) OVER (PARTITION BY job_family) AS ratio
FROM 
    t
WHERE 
    country != 'India'
GROUP BY 
    job_family, country;

In this modified query:

  • We add a WHERE clause to exclude rows where the country is India.
  • The rest of the query remains the same.

Conclusion

In this article, we’ve explored how to calculate the ratio of CTC for each job family internationally compared to India using SQL Server. By employing aggregations and window functions, we can compare the CTC values within each group and extract valuable insights from our dataset.

We hope this in-depth analysis has provided a comprehensive understanding of the problem and its solution. With practice and experience, you’ll become proficient in using these techniques to solve complex data analysis problems.


Last modified on 2024-02-22