Page 269 - PYTHON-12
P. 269

POINTS TO REMEMBER
               •  If the alias_name contains spaces, you must enclose it in quotes.
               •  It is acceptable to use spaces when you are aliasing a column name. However, it is not generally a good
                  practice to use spaces when you are aliasing a table name.
               •  The alias_name is only valid within the scope of the SQL statement.

                Alias name can be given to a mathematical expression also:


                 For example,
                     SELECT 22/7 as PI;                         Output:       +------------+
                                                                               |        PI       |

                                                                              +------------+
                                                                               |   3.1429   |

                                                                              +------------+

              12.16 PUTTING TEXT IN THE QUERY OUTPUT

              In  order  to  get  an  organized  output  from  a  SELECT  query,  we  can  include  some  user-defined
              columns at runtime. These columns are displayed with a valid text, symbols and comments in the
              output only. These included columns will appear as column heads along with the contents for that
              column.

              This makes the query output more presentable by giving a formatted output.
              For example,  SELECT Rollno, Name, ‘was born on’,DOB
                                                                     Text to be displayed
                            FROM student;
              The above command, on execution, shall display the text “was born on” with every record (tuple)
              of the table.
              Resultant table: student

              Rollno  Name               was born on       DOB
                 1.   Raj Kumar          was born on  17-Nov-2000
                 2.   Deep Singh         was born on  22-Aug-1996
                 3.   Ankit Sharma       was born on  02-Feb-2000
                 4.   Radhika Gupta      was born on  03-Dec-1999
                 5.   Payal Goel         was born on  21-April-1998
                 6.   Diksha Sharma      was born on  17-Dec-1999
                 7.   Gurpreet Kaur      was born on  04-Jan-2000
                 8.   Akshay Dureja      was born on  05-May-1997
                 9.   Shreya Anand       was born on  08-Oct-1999
                                                                                                                  Relational Database and SQL
                10.   Prateek Mittal     was born on  25-Dec-2000
              10 rows in a set (0.02 sec)


              12.17 SQL SPECIAL OPERATORS

              Apart from several standard library functions discussed earlier, there are some special operators
              in SQL that perform some specific functions.


                                                                                                            12.39
   264   265   266   267   268   269   270   271   272   273   274