Page 262 - PYTHON-12
P. 262

For example,                              Resultant table: student
                                                                                           Science displayed
               SELECT  DISTINCT Stream from                       Stream                       once only
               student;                                         Science
                                                                Commerce
                                                                Humanities
                                                                Vocational
                                                        4 rows in a set (0.02 sec)
               12.14.2 SQL Operators

               While working with SELECT statement using WHERE clause, condition-based query can be carried
               out using four types of SQL operators:

                    (a)  Arithmetic Operators
                   (b)  Relational Operators

                    (c)  Logical Operators
                   (d)  Special Operators

                                        Table 12.3 SQL Operators and their Functions
                OPERATOR/FUNCTION                                     DESCRIPTION
                COMPARISON OPERATORS
                =, >, <, >=, <=, <>        Used in Conditional expressions.
                LOGICAL OPERATORS
                AND/OR/NOT                 Used in Conditional expressions.
                SPECIAL OPERATORS          Used in Conditional expressions.
                BETWEEN                    Checks whether an attribute value is within a range.
                IS NULL                    Checks whether an attribute value is null.
                LIKE                       Checks whether an attribute matches a given string pattern.
                IN                         Checks whether an attribute value matches any value with a given list.
                DISTINCT                   Permits only unique values. Eliminates duplicate ones.
                AGGREGATE FUNCTIONS        Used with SELECT to return mathematical results/values on the basis of the operation
                                           performed on the columns.
                COUNT                      Returns the total number of records with non-null values for a given column.
                MIN                        Returns the minimum/lowest attribute value found in a given column.
                MAX                        Returns the maximum/highest attribute value found in a given column.
                SUM                        Returns the sum of all the values for a given column.
                AVG                        Returns the average of all the values for a given column.

                    (a)  Arithmetic Operators
           Computer Science with Python–XII  12.32        mysql> SELECT 5 + 10 FROM DUAL;
                        Arithmetic operators are used to perform simple arithmetic operations like addition (+),
                         subtraction (–), multiplication (*), division (/) and modulus (%). These operators are
                         used with conditional expressions and for performing simple mathematical calculations.
                         The arithmetic operators with SELECT command are used to retrieve rows computed
                         with or without reference to any table.




                        The above statement shall evaluate the expression 5 + 10 and returns the value 15 as the
                         result.
   257   258   259   260   261   262   263   264   265   266   267