Tech Layoffs

Tech companies have been laying off employees after a large surge of hires in the past few years.

Write a query to determine the percentage of employees that were laid off from each company.

Output should include the company and the percentage (to 2 decimal places) of laid off employees.

Order by company name alphabetically.

table name: tech_layoffs

Explanation: We have given a table named tech_layoffs in which three columns are 

  • company - the name of the company,
  • company_size - number of employees worked in the company,
  • employees_fired - number of employees who have been fired in the company.

We need to find the percentage of employees that were fired from the company. 

Formula

100.0 * employees_fired / company_size

Solution:

SELECT company,
cast(((100.0 * employees_fired)/company_size) as decimal(18,2)) as per  
FROM tech_layoffs
order by company

Output:

SQL Script:

USE [AnalystBuilder]
GO
/****** Object:  Table [dbo].[tech_layoffs]    Script Date: 04-02-2024 19:02:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tech_layoffs](
	[company] [nvarchar](50) NULL,
	[company_size] [bigint] NULL,
	[employees_fired] [bigint] NULL
) ON [PRIMARY]
GO
INSERT [dbo].[tech_layoffs] ([company], [company_size], [employees_fired]) VALUES (N'Apple', 147000, 0)
GO
INSERT [dbo].[tech_layoffs] ([company], [company_size], [employees_fired]) VALUES (N'Microsoft', 181000, 6000)
GO
INSERT [dbo].[tech_layoffs] ([company], [company_size], [employees_fired]) VALUES (N'Google', 139500, 15000)
GO
INSERT [dbo].[tech_layoffs] ([company], [company_size], [employees_fired]) VALUES (N'Amazon', 1300000, 12000)
GO
INSERT [dbo].[tech_layoffs] ([company], [company_size], [employees_fired]) VALUES (N'Facebook', 60750, 11000)
GO
INSERT [dbo].[tech_layoffs] ([company], [company_size], [employees_fired]) VALUES (N'Tesla', 70000, 1000)
GO

Comments (1)
Name - 05/04/2025 21:07
katana