slide môn học MySQL bài 6 using basic functions in MySQL

30 4 0
  • Loading ...
1/30 trang

Thông tin tài liệu

Ngày đăng: 30/11/2016, 22:11

Using Basic Functions in MySQL Session 12 Review - I    Joining of tables means combining two or more data or records of different tables of same database into one comprehensive structure The field with the primary key of a table is used for joining tables by referring it as a reference key for the next table Advantages of joining of tables are:     Greater ease of manipulation Increases speed in access Reduces data redundancy The tables are joined either with the WHERE clause used with SELECT command or by using JOIN keyword MySQL Database / Session 12 / Slide of 30 Review - II     An equi-join can also be called as INNER JOIN An INNER JOIN behaves same like ‘,’ which is used for joining tables When using INNER JOIN the common field of the joining tables should have the matching value An OUTER JOIN is used to join two tables, a source and joining table, which have one or more columns in common A self-join is a query in which a value of a table column is joined or compared to itself MySQL Database / Session 12 / Slide of 30 Objectives      Use GROUP BY and HAVING clause in MySQL queries Use the Mathematical functions Use the Date functions Use the String functions Use the system information function MySQL Database / Session 12 / Slide of 30 Basics of Using Functions   The functions used in MySQL are similar to any other programming language A function is used in two ways in a MySQL command:  Value to be retrieved  Part of a WHERE clause MySQL Database / Session 12 / Slide of 30 Using GROUP BY and HAVING Clause     GROUP BY clause groups the rows with similar values for a specific column into a single row HAVING clause is used to define the result set based on some set of calculations GROUP BY clause is used with aggregate functions The aggregate functions are AVG, COUNT, MAX, MIN, and SUM MySQL Database / Session 12 / Slide of 30 Aggregate Functions - I   AVG function  Returns the average of the values of the argument  The syntax for obtaining the average of the argument is: AVG(expression) COUNT function  Returns the number of times the argument is not NULL  The syntax for obtaining the count is: COUNT(expression) MySQL Database / Session 12 / Slide of 30 Aggregate Functions - II  MIN function  Returns the minimum value of the expression  The syntax for obtaining the smallest value is: MIN(expression)  SUM function  Returns the sum of the values in the expression  The syntax for obtaining the sum is: SUM(expression) MySQL Database / Session 12 / Slide of 30 Mathematical Functions using MySQL - I   MySQL provides with mathematical functions that operate on data and return numerical value Ceiling function  Returns the smallest integer value greater than the argument X  The syntax for obtain the arc tangent of an argument X is: CEILING(X)  COS function  Returns cosine of an argument  The syntax for obtaining the cosine of an argument X is: COS(X) MySQL Database / Session 12 / Slide of 30 Mathematical Functions using MySQL - II  CRC function  Calculates a cyclic redundancy check value  Returns a 32 bit unsigned value  The syntax for obtaining the cyclic redundancy value of an argument X is: CRC32(X) MySQL Database / Session 12 / Slide 10 of 30 Date Functions in MySQL - II   CURDATE function  Returns the current date in the format YYYY-MM-DD or YYYYMMDD format  The syntax for obtaining the current date is: CURDATE() DAY function  Returns the day of the month for the specified date  Range is from to 31  The syntax for obtaining the day of the month is: DAY(date) MySQL Database / Session 12 / Slide 16 of 30 Date Functions in MySQL - III   DATEDIFF function  Returns the number of days between a start date and end date  The syntax for obtaining the date difference is: DATEDIFF(expr1,expr2) DAYNAME function  Returns the name of the weekday for a date  The syntax for obtaining the name of the week day is: DAYNAME(date) MySQL Database / Session 12 / Slide 17 of 30 Date Functions in MySQL - IV   MONTHNAME function  Returns the name of the month for the date  The syntax for obtaining the month name is: MONTHNAME (date) YEAR function  Returns the year for the date  The syntax for obtaining the year for a date argument is: YEAR (date) MySQL Database / Session 12 / Slide 18 of 30 String Functions Using MySQL - I   String Functions operate on character type of data ASCII function  Returns the numeric value of the leftmost character of the string  The syntax for obtaining the ASCII value is: ASCII(string) MySQL Database / Session 12 / Slide 19 of 30 String Functions Using MySQL - II  BIN function  Returns a string representation of the binary value of N, where N is the BIGINT number  The syntax for obtaining the string representation is: BIN(string)  CONCAT function  Returns a string after concatenating the arguments  The syntax to concatenate is: CONCAT(STR1,STR2, ) MySQL Database / Session 12 / Slide 20 of 30 String Functions Using MySQL - III   BIT_LENGTH function  Returns the length of the string specified as the argument  The syntax for obtaining the length of the string in bits is: BIT_LENGTH(string) COMPRESS function  Compresses a string  The syntax for compressing a string is: COMPRESS(string) MySQL Database / Session 12 / Slide 21 of 30 String Functions Using MySQL - IV   LENGTH function  Returns the length of a string in bytes  The syntax for obtaining the length of the string is: LENGTH(str) CHAR function  Returns a string consisting of character given by the code value of the integers  The syntax for obtaining the string of characters is: CHAR(N, ) MySQL Database / Session 12 / Slide 22 of 30 String Functions Using MySQL - V   FIELD function  Returns the index of the string in the other strings specified as argument  The syntax for obtaining the string is: FIELD(string1,string2, ) INSERT function  Adds a string to a string at a specified position  The syntax for insert function is: INSERT(str,pos,len,newstr) MySQL Database / Session 12 / Slide 23 of 30 String Functions Using MySQL - VI  LOWER function  Changes the string entered into lowercase  The syntax for converting into lower case is: LOWER(str) MySQL Database / Session 12 / Slide 24 of 30 System Information Functions using MySQL - I   System information functions returns the system related information BENCHMARK function  Executes the expression entered as the argument repeatedly the number of times specified in the argument  The syntax for benchmark is: BENCHMARK(count, expr) MySQL Database / Session 12 / Slide 25 of 30 System Information Functions using MySQL - II   CHARSET function  Returns the character set of the argument  The syntax for obtaining the character set of a string is: CHARSET (str) CONNECTION_ID function  Returns the thread ID for the connection  The syntax for obtaining the thread ID is: CONNECTION_ID () MySQL Database / Session 12 / Slide 26 of 30 System Information Functions using MySQL - III  CURRENT_USER function  Returns the username and the hostname of the current session  The syntax for viewing the hostname and the username is: CURRENT_USER()  DATABASE function  Returns the name of the current database  The syntax for obtaining the database name is: DATABASE() MySQL Database / Session 12 / Slide 27 of 30 System Information Functions using MySQL - IV  VERSION function  Returns version of MySQL  The syntax for obtaining the version is: VERSION() MySQL Database / Session 12 / Slide 28 of 30 Summary – I     The functions are used in two ways in the SQL queries:  In place of the column name  In the WHERE clause The GROUP BY clause is used with the functions to group the data on a specific constraint The mathmematical functions are used to operate on numbers The examples of mathematical functions are COS, SIN, TAN, and several others The mathematical fuction returns a NULL value if error occurs while processing MySQL Database / Session 12 / Slide 29 of 30 Summary – II    The string function operates on character type of data The date functions are used to perfom computations on the date type fo data These fucntions are used to add the date, subtract the date, and extract a part of the date The system functions are used to obtain sytem related information MySQL Database / Session 12 / Slide 30 of 30 [...]... obtaining the year for a date argument is: YEAR (date) MySQL Database / Session 12 / Slide 18 of 30 String Functions Using MySQL - I   String Functions operate on character type of data ASCII function  Returns the numeric value of the leftmost character of the string  The syntax for obtaining the ASCII value is: ASCII(string) MySQL Database / Session 12 / Slide 19 of 30 String Functions Using MySQL. .. length of the string specified as the argument  The syntax for obtaining the length of the string in bits is: BIT_LENGTH(string) COMPRESS function  Compresses a string  The syntax for compressing a string is: COMPRESS(string) MySQL Database / Session 12 / Slide 21 of 30 String Functions Using MySQL - IV   LENGTH function  Returns the length of a string in bytes  The syntax for obtaining the length... the string is: LENGTH(str) CHAR function  Returns a string consisting of character given by the code value of the integers  The syntax for obtaining the string of characters is: CHAR(N, ) MySQL Database / Session 12 / Slide 22 of 30 String Functions Using MySQL - V   FIELD function  Returns the index of the string in the other strings specified as argument  The syntax for obtaining the string is:... FIELD(string1,string2, ) INSERT function  Adds a string to a string at a specified position  The syntax for insert function is: INSERT(str,pos,len,newstr) MySQL Database / Session 12 / Slide 23 of 30 String Functions Using MySQL - VI  LOWER function  Changes the string entered into lowercase  The syntax for converting into lower case is: LOWER(str) MySQL Database / Session 12 / Slide 24 of 30 System Information... syntax for obtaining the database name is: DATABASE() MySQL Database / Session 12 / Slide 27 of 30 System Information Functions using MySQL - IV  VERSION function  Returns version of MySQL  The syntax for obtaining the version is: VERSION() MySQL Database / Session 12 / Slide 28 of 30 Summary – I     The functions are used in two ways in the SQL queries:  In place of the column name  In the WHERE... Using MySQL - II  BIN function  Returns a string representation of the binary value of N, where N is the BIGINT number  The syntax for obtaining the string representation is: BIN(string)  CONCAT function  Returns a string after concatenating the arguments  The syntax to concatenate is: CONCAT(STR1,STR2, ) MySQL Database / Session 12 / Slide 20 of 30 String Functions Using MySQL - III   BIT_LENGTH... 30 System Information Functions using MySQL - I   System information functions returns the system related information BENCHMARK function  Executes the expression entered as the argument repeatedly the number of times specified in the argument  The syntax for benchmark is: BENCHMARK(count, expr) MySQL Database / Session 12 / Slide 25 of 30 System Information Functions using MySQL - II   CHARSET... syntax for obtaining the square root of an argument is: SQRT(X) MySQL Database / Session 12 / Slide 14 of 30 Date Functions in MySQL - I   MySQL provides with date functions that operate on date and time data type ADDDATE function  Add two date expressions  The syntax for adding two date expressions is: ADDDATE(expr1,days) MySQL Database / Session 12 / Slide 15 of 30 Date Functions in MySQL - II ... syntax for obtaining the character set of a string is: CHARSET (str) CONNECTION_ID function  Returns the thread ID for the connection  The syntax for obtaining the thread ID is: CONNECTION_ID () MySQL Database / Session 12 / Slide 26 of 30 System Information Functions using MySQL - III  CURRENT_USER function  Returns the username and the hostname of the current session  The syntax for viewing the hostname... Mathematical Functions using MySQL - IV  LOG function  Enables a user to enter one or two arguments  The syntax for specifying one argument in a LOG function is: LOG(X)  MOD function  Returns the remainder of the first argument divided by the second  The syntax for obtaining the remainder is: MOD(X,Y) MySQL Database / Session 12 / Slide 12 of 30 Mathematical Functions using MySQL - V  POWER function
- Xem thêm -

Xem thêm: slide môn học MySQL bài 6 using basic functions in MySQL , slide môn học MySQL bài 6 using basic functions in MySQL , slide môn học MySQL bài 6 using basic functions in MySQL

Gợi ý tài liệu liên quan cho bạn

Nạp tiền Tải lên
Đăng ký
Đăng nhập