Essential SQL Questions and Queries
Essential SQL Questions and Queries
To remove a student record with Stud_id 100, the query is 'DELETE FROM student WHERE Stud_id = 100;'. To add a new student, Rajeev, the query is 'INSERT INTO student (Stud_id, Name, Class, Stream) VALUES (123, 'Rajeev', 12, 'Science');'.
To calculate the value, the query is 'SELECT ITEM, QTY * PRICE AS 'AMOUNT' FROM STATIONERY WHERE ITEMNO = 402;'. This multiplies QTY by PRICE for the item with ITEMNO 402.
Use the query 'SELECT prize_money, game_name, player_name FROM GAMES INNER JOIN PLAYERS ON GAMES.game_id = PLAYERS.game_id;'. This joins both tables on shared game IDs.
To make Vcode a primary key, use 'ALTER TABLE Rent_cab ADD PRIMARY KEY (Vcode);'. To increase charges by 10%, use 'UPDATE Rent_cab SET charges = charges * 1.1;'.
The query is 'SELECT ITEMNO, ITEM FROM STATIONERY WHERE DISTRIBUTOR = 'Classic Plastics' AND PRICE > 10;'. This command filters the Stationery table for items meeting both specified conditions.
The query is 'SELECT game_name, prize_money FROM GAMES WHERE prize_money IS NOT NULL;'. This filters for games with known prize money.
The SQL query to calculate the total quantity of items grouped by distributor is 'SELECT DISTRIBUTOR, SUM(QTY) FROM STATIONERY GROUP BY DISTRIBUTOR;'.
The query to delete entries is 'DELETE FROM Rent_cab WHERE maker = 'Carus';'. This statement removes all cabs whose maker is 'Carus'.
To create a database named Admin, the SQL query is 'CREATE DATABASE Admin;'. To create a table named users with columns User_id (int), User_name (varchar(20)), and Password (varchar(10)), the query is 'CREATE TABLE users (User_id INT, User_name VARCHAR(20), Password VARCHAR(10));'.
To display average games played, use 'SELECT game_type, AVG(num_of_games) FROM GAMES GROUP BY game_type;'. For unique types, use 'SELECT DISTINCT type FROM GAMES;'.

