Basics: Most Commonly used Queries.
Aditya Dabrase
Business & Data Analytics Professional with 4+ years of experience in Excel, SQL, Python, and R
A few basic SQL queries for the record, that are frequently used to retrieve, analyze, and manipulate data stored in databases.
Here are some commonly used queries (in the context of retail for examples, my usual experience and simplicity ) :
1. Basic Data Retrieval:
SELECT * FROM products;
2. Filtering Data:
SELECT * FROM orders WHERE order_status = 'Shipped';
3. Sorting Data:
SELECT * FROM customers ORDER BY last_name ASC;
4. Aggregate Functions:
SELECT SUM(order_total) AS total_sales FROM orders;
5. Grouping and Aggregation:
SELECT category, COUNT(*) AS product_count FROM products GROUP BY category;
6. Joins:
SELECT orders.order_id, customers.customer_name
FROM orders
INNER JOIN customers ON orders.customer_id = customers.customer_id;
领英推荐
7. Subqueries:
SELECT product_name
FROM products
WHERE category_id IN (SELECT category_id FROM categories WHERE category_name = 'Electronics');
8. Filtering with Date and Time:
SELECT * FROM orders WHERE order_date >= '2022-01-01' AND order_date < '2022-02-01';
9. Updating Records:
UPDATE products SET price = price * 1.1 WHERE category = 'Apparel';
10. Inserting Records:
INSERT INTO customers (customer_name, email) VALUES ('John Doe', '[email protected]');
11. Deleting Records:
DELETE FROM customers WHERE customer_id = 101;
12. Combining Multiple Conditions:
SELECT * FROM products WHERE price > 50 AND stock_quantity > 0;
13. Top N Records:
SELECT * FROM products ORDER BY sales DESC LIMIT 10;
These SQL queries provide a foundation for managing and extracting valuable insights from retail databases. Depending on specific business requirements, these queries can be customized and extended to suit the analytical needs of a retail environment. What are the top queries that you use daily? feel free to discuss/reach out if you have any questions.