MySQL Basic operation exercise

Source: Internet
Author: User

1 Create TableEmployee (namevarchar( -), SexChar(2), ageint, addressvarchar( -));2 3 Insert  intoEmployeeValues('Zhang San','female', +,'Beijing');4 Insert  intoEmployeeValues('John Doe','male', -,'Shanghai');5 Insert  intoEmployeeValues('Harry','female', -,'Guangzhou');6 Insert  intoEmployeeValues('Shili','female', -,'Beijing');7 Insert  intoEmployeeValues('Harry','male', A,'Beijing');8 Insert  intoEmployeeValues('Zhao Qi','male', -,'Shanghai');9 Insert  intoEmployeeValues('Zhang Si','female', at,'Beijing');Ten  One#(1). Write the SQL statement and query all employees older than 20 (2 points) A Select * fromEmployeewhereAge> -; -#(2). Write the SQL statement and query all female employees younger than 25 years old (3 points) - Select * fromEmployeewhereSex='female'  andAge< -; the#(3). Write the SQL statement to count the number of male and female employees (3 points) -#Countfunction - Select Count(*) fromemployee; #统计表元素个数 - Select Count(*) fromEmployeewhereSex='female'; #统计女生个数 + SelectSexCount(*) fromEmployeeGroup  bysex;#Group  bySex groups by gender, grouped by sex tags - SelectSexCount(*) asNum fromEmployeeGroup  bysex;# asalias from +  A#(4). Write SQL statements to get employee information in reverse chronological order (3 points) at Select *  fromEmployeeOrder  byAgedesc; -#(5). Write the SQL statement to get the name of the employee who has a duplicate (3 points) - SELECT *   -    fromEmployee -  WHERENameinch(SELECTname -                    fromEmployee in                  GROUP  byname -                  having COUNT(*)> 1)   to#(6). Write the SQL statement and query all the employees surnamed Zhang (3 points) + Select *  fromEmployeewhereName like '% sheet%'#模糊查询, with a single word - Select *  fromEmployeewhereName like 'Zhang%'; #只要姓张 the #占位符写法 * Select *  fromEmployeewhereName like 'Zhang __'; $#(7). Write the SQL statement to find the first 3 records of Beijing (3 points)Panax Notoginseng Select *  fromEmployeewhereAddress='Beijing'  Order  byNameASCLimit0,3; #从下标几开始, several - Select *  fromEmployee limit3,3; the#(8). Write the SQL statement and query the total number of employees (3 points) + Select Count(*) asAllnum fromemployee; A#(9). Write the SQL statement and insert a record (2 points) into the table the Insert  intoEmployee (name,sex,age,address)Values('77','male', -,'Shenzhen'); +#(Ten). Write the SQL statement and modify the address of the employee Zhang Xi Nanjing (2 min.) - UpdateEmployeeSetAddress='Nanjing' whereName='Zhang Si'; $#( One). Write out the SQL statement to delete female employees older than 24 years (2) $ Delete  fromEmployeewhereAge> -  andSex='female';
View Code

MySQL Basic operation exercise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.