The document contains examples of SQL queries to retrieve data from different database tables based on various conditions. The queries demonstrate how to select records by filtering on column values, sorting results, and joining data from multiple tables.
The document contains examples of SQL queries to retrieve data from different database tables based on various conditions. The queries demonstrate how to select records by filtering on column values, sorting results, and joining data from multiple tables.
The document contains examples of SQL queries to retrieve data from different database tables based on various conditions. The queries demonstrate how to select records by filtering on column values, sorting results, and joining data from multiple tables.
To display details of all models in the Model table in ascending
order of Model_id. select * from Model order by Model_id; -- Creating the Model table CREATE TABLE ranjaan.Model ( Model_id INT PRIMARY KEY, Model_name VARCHAR(255), Manufacturer VARCHAR(255), Release_year INT );
-- Displaying details of models in ascending order of
Model_id SELECT * FROM ranjaan.Model ORDER BY Model_id ASC; 2. To display details of those models whose cost is below 20,000. select * from Model where Cost < 20000; -- Create the database named ranjaan (if it doesn't exist) CREATE DATABASE IF NOT EXISTS ranjaan;
-- Switch to the ranjaan database
USE ranjaan;
-- Create the Model table with a column for Cost
CREATE TABLE Model ( Model_id INT PRIMARY KEY, Model_name VARCHAR(255), Cost DECIMAL(10, 2) -- Assuming cost is in decimal format );
-- Insert some sample data
INSERT INTO Model (Model_id, Model_name, Cost) VALUES (1, 'Model A', 15000.00), (2, 'Model B', 25000.00), (3, 'Model C', 18000.00), (4, 'Model D', 22000.00); -- Display details of models whose cost is below 20,000 SELECT * FROM Model WHERE Cost < 20000; 3. To display the records of Product Table where prod office begins with the letter 'K'. select * from Product where Prod _office like "K%" -- Create the database named YourDatabaseName (replace with your desired name) CREATE DATABASE IF NOT EXISTS YourDatabaseName;
-- Display records where Prod_office begins with the letter 'K'
SELECT * FROM Product WHERE Prod_office LIKE 'K%'; 16. To display all the records of Product table on the basis of price in descending order. select * from Product order by Price desc; -- Create a new database (if not exists) CREATE DATABASE IF NOT EXISTS YourDatabaseName;
-- Switch to the new database
USE YourDatabaseName;
-- Create the Product table (if not exists)
CREATE TABLE IF NOT EXISTS Product ( ProductID INT PRIMARY KEY, PName VARCHAR(255) NOT NULL, Price DECIMAL(10, 2) NOT NULL, Quantity INT NOT NULL ); -- Display all records of Product table on the basis of price in descending order SELECT * FROM Product ORDER BY Price DESC; 17. To display the details of those items whose supplier code (SNo) is 104 or quantity in stock table is more than 100. -- Create a new database (if not exists) CREATE DATABASE IF NOT EXISTS YourDatabaseName;
-- Switch to the new database
USE YourDatabaseName;
-- Create the Stock table (if not exists)
CREATE TABLE IF NOT EXISTS Stock ( ItemID INT PRIMARY KEY, ItemName VARCHAR(255) NOT NULL, SNo INT NOT NULL, Quantity INT NOT NULL ); -- Display details of items from Stock table where SNo is 104 or Quantity is more than 100 SELECT * FROM Stock WHERE SNo = 104 OR Quantity > 1 18. To display ItemNo and itemName of those items from stock table whose price is more than 5. select ItemNo, ItemName from Stock where Price > 5; -- Create a new database (if not exists) CREATE DATABASE IF NOT EXISTS YourDatabaseName;
-- Switch to the new database
USE YourDatabaseName;
-- Create the Stock table (if not exists)
CREATE TABLE IF NOT EXISTS Stock ( ItemNo INT PRIMARY KEY, ItemName VARCHAR(255) NOT NULL, Price DECIMAL(10, 2) NOT NULL ); -- Display ItemNo and ItemName of items from Stock table where Price is more than 5 SELECT ItemNo, ItemName FROM Stock WHERE Price > 5; 19. To display details of all items in the Stock table in ascending order of stockdate. select * from Stock order by StockDate; -- Create a new database (if not exists) CREATE DATABASE IF NOT EXISTS YourDatabaseName;
-- Switch to the new database
USE YourDatabaseName;
-- Create the Stock table (if not exists)
CREATE TABLE IF NOT EXISTS Stock ( ItemID INT PRIMARY KEY, ItemName VARCHAR(255) NOT NULL, StockDate DATE NOT NULL ); -- Display details of all items from Stock table in ascending order of StockDate SELECT * FROM Stock ORDER BY StockDate
Ultimate Snowflake Architecture for Cloud Data Warehousing: Architect, Manage, Secure, and Optimize Your Data Infrastructure Using Snowflake for Actionable Insights and Informed Decisions (English Edition)