This question was asked in Interview at black rock. Read more
Company: BlackRock
CTC: 26LPA
Source: LinkedIn
-- Create the Products table
CREATE TABLE Products (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(100),
Category VARCHAR(50),
Price DECIMAL(10, 2)
);
-- Insert sample data into Products table
INSERT INTO Products VALUES
(1, 'Laptop', 'Electronics', 800.00),
(2, 'Laptop', 'Electronics', 300.00),
(3, 'Headphones', 'Electronics', 50.00),
(4, 'Laptop', 'Electronics', 800.00),
(5, 'Tablet', 'Electronics', 300.00),
(6, 'Tablet', 'Electronics', 300.00),
(7, 'Chair', 'Furniture', 120.00),
(8, 'Table', 'Furniture', 250.00),
(9, 'Laptop', 'Electronics', 800.00),
(10, 'Desk', 'Furniture', 200.00);
See this code on db-fiddle
SELECT
ProductName,
COUNT(*) AS Frequency
FROM
Products
GROUP BY
ProductName
ORDER BY
Frequency DESC
LIMIT 1;
We have selected ProductName
along with the count of rows as Frequency
, grouping the data by ProductName
. To display the product with the highest frequency at the top of the table, we used ORDER BY Frequency DESC
. Finally, the LIMIT
clause ensures that only the top record is selected.
I hope this would have been helpful for you, consider sharing it with your friends. thank you.
Hi, I am Vishal Jaiswal, I have about a decade of experience of working in MNCs like Genpact, Savista, Ingenious. Currently i am working in EXL as a senior quality analyst. Using my writing skills i want to share the experience i have gained and help as many as i can.
Welcome to Day 13 of Learning Python for Data Science! Today, we’re focusing on three…
Test your understanding of Python Data Structure, which we learned in our previous lesson of…
Welcome to Day 12 of Learning Python for Data Science. Today, we’ll dive into Pandas,…
NumPy Array in Python is a powerful library for numerical computing in Python. It provides…
Welcome to Day 9 of Learning Python for Data Science. Today we will explore comprehensions,…
Test your understanding of Python Data Structure, which we learned in our previous lesson of…