SQL Query Interview Questions

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
dimkr
Posts: 2024
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 38 times
Been thanked: 929 times

Re: SQL Query Interview Questions

Post by dimkr »

Total number of items purchased by each customer or number of orders (assuming one row = one order) by each customer?

Code: Select all

SELECT CustomerID, SUM(Quantity) 
FROM Orders 
GROUP BY CustomerID;

or

Code: Select all

SELECT CustomerID, COUNT(*) 
FROM Orders 
GROUP BY CustomerID;
User avatar
rockedge
Site Admin
Posts: 5859
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2102 times
Been thanked: 2196 times
Contact:

Re: SQL Query Interview Questions

Post by rockedge »

Query for duplicate records:

Code: Select all

SELECT 
    CustomerID, 
    COUNT(CustomerID)
FROM
    Orders
GROUP BY CustomerID
HAVING COUNT(CustomerID) > 1;
Screenshot(26).jpg
Screenshot(26).jpg (40.82 KiB) Viewed 613 times
User avatar
user1234
Posts: 413
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 154 times
Been thanked: 88 times

Re: SQL Query Interview Questions

Post by user1234 »

@rockedge, I am sorry to get off topic, but which program is this that you are using for running SQL queries? I am interested as we've just been taught how to run SQL queries in OpenOffice Database, but I am unsure if that is the program one uses for SQL in real life.

Thanks!

Regards
user1234 :D

PuppyLinux 🐾 gives new life to old computers ✨

User avatar
rockedge
Site Admin
Posts: 5859
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2102 times
Been thanked: 2196 times
Contact:

Re: SQL Query Interview Questions

Post by rockedge »

@user1234 I am using phpmyadmin to work with MySQL databases!

Post Reply

Return to “Programming”