Page 331 - Informatics_Practices_Fliipbook_Class12
P. 331

Table: Trains
                                        +-----------+--------------------------+--------------+-------------+
                                        | TNO      | TName                      | Departure | Arrival     |
                                        +-----------+--------------------------+--------------+-------------+
                                        | 112300 | Centenary Express | Delhi        | Mumbai |
                                        | 135799 | Passenger                | Delhi         | Alwar      |
                                        | 918273 | Jammu Mail             | Amritsar   | Jammu    |
                                        | 403822 | Sushant Mail           | Ranchi       | Delhi       |
                                        +-----------+--------------------------+--------------+-------------+

            Write SQL statements to perform the following tasks:
                  (i)  Display the names of trains that depart from Delhi

                Ans.  SELECT TName FROM Trains

                          WHERE Departure = "Delhi";
                 (ii)  Display the Passenger Names, date of travel, and corresponding Train Names for all passengers.

                Ans.  SELECT PName, TravelDate, TName FROM Passengers P, Trains T

                          WHERE P.TNO = T.TNO;
                 (iii)  Display the count of male and female passengers.

                Ans.  SELECT Gender, COUNT(*) FROM Passengers

                         GROUP BY Gender

                         HAVING Gender IN ('M','F');
                 (iv)  Display the name of the passenger whose age is not known.
                Ans.  SELECT PNAME FROM Passengers

                          WHERE AGE IS NULL;

                 (v)  Change the Arrival station of Sushant Mail to Patna
                Ans.  UPDATE Trains

                          SET Arrival = "Patna"

                          WHERE TName = "Sushant Mail";
                 (vi)  Delete the record of passengers who have travelled in the year 2023.

                Ans.  DELETE FROM Passengers

                          WHERE TRAVELDATE LIKE "2023%";



















                                                                                                      Practical  317
   326   327   328   329   330   331   332   333   334   335   336