w3resource_MySQL练习题:Basic_select_statement

1. Write a query to display the names (first_name, last_name) using alias name "First Name", "Last Name"
Sample table: employees
  1. -- 要点:as设置别名,as可省略
  2. select first_name as "First Name", last_name as "Last Name"
  3. from employees

  

2. Write a query to get unique department ID from employee table
Sample table: employees
  1. -- 要点:select时添加distinct获取唯一值
  2. select distinct department_id
  3. from employees
3. Write a query to get all employee details from the employee table order by first name, descending
Sample table: employees
  1. -- 要点:order by进行排序,desc进行降序排序
  2. select *
  3. from employees
  4. order by first_name desc
4. Write a query to get the names (first_name, last_name), salary, PF of all the employees (PF is calculated as 15% of salary)
Sample table: employees
  1. -- 要点:select中可以进行数学运算
  2. select first_name, last_name, salary, salary*0.15 as PF
  3. from employees

  

5. Write a query to get the employee ID, names (first_name, last_name), salary in ascending order of salary
Sample table: employees
  1. -- 要点:order by + asc
  2. select employee_id, first_name, last_name, salary
  3. from employees
  4. order by salary asc

  

6. Write a query to get the total salaries payable to employees
Sample table: employees
  1. -- 要点:sum()加总
  2. select sum(salary)
  3. from employees

  

7. Write a query to get the maximum and minimum salary from employees table
Sample table: employees
  1. -- 要点:max() + min()
  2. select max(salary), min(salary)
  3. from employees
8. Write a query to get the average salary and number of employees in the employees table
Sample table: employees
  1. -- 要点:avg()均值 + count()计数
  2. select avg(salary), count(*)
  3. from employees
9. Write a query to get the number of employees working with the company
Sample table: employees
  1. -- 要点:count()
  2. select count(*)
  3. from employees
10. Write a query to get the number of jobs available in the employees table
Sample table: employees
  1. -- 要点:count() + distinct
  2. select count(distinct job_id)
  3. from employees

  

11. Write a query get all first name from employees table in upper case
Sample table: employees
  1. -- 要点:upper()
  2. select upper(first_name)
  3. from employees

  

12. Write a query to get the first 3 characters of first name from employees table
Sample table: employees
  1. -- 要点:left()从左开始取字符
  2. select left(first_name, 3)
  3. from employees
13. Write a query to calculate 171*214+625
  1. -- 要点:select可直接计算
  2. select 171*214+625
14. Write a query to get the names (for example Ellen Abel, Sundar Ande etc.) of all the employees from employees table
Sample table: employees
  1. -- 要点:concat()两列字符串组合
  2. select concat(first_name, ' ', last_name)
  3. from employees

  

15. Write a query to get first name from employees table after removing white spaces from both side
Sample table: employees
  1. -- 要点:trim()去除两边空格
  2. select trim(first_name)
  3. from employees

  

16. Write a query to get the length of the employee names (first_name, last_name) from employees table
Sample table: employees
  1. -- 要点:length()计算长度
  2. select length(first_name)+first_name(last_name)
  3. from employees
17. Write a query to check if the first_name fields of the employees table contains numbers
Sample table: employees
  1. -- 要点:where里使用 REGEXP 实现正则效果
  2. select *
  3. from employees
  4. where first_name REGEXP '[0-9]'

  

18. Write a query to select first 10 records from a table
Sample table: employees
  1. -- 要点:limit限制取数量
  2. select *
  3. from employees
  4. limit 10

  

19. Write a query to get monthly salary (round 2 decimal places) of each and every employee
Note : Assume the salary field provides the 'annual salary' information.
Sample table: employees
  1. -- 要点:round()实现小数位控制
  2. select first_name, last_name, round(salary/12, 2) as 'Monthly Salary'
  3. from employees

w3resource_MySQL练习:Basic_select_statement的更多相关文章

  1. w3resource_MySQL练习:Joins

    w3resource_MySQL练习题:Joins 1. Write a query to find the addresses (location_id, street_address, city, ...

  2. w3resource_MySQL练习:Subquery

    w3resource_MySQL练习题:Subquery 1. Write a query to find the name (first_name, last_name) and the salar ...

  3. w3resource_MySQL练习: Aggregate_functions

    w3resource_MySQL练习题:Aggregate_functions   1. Write a query to list the number of jobs available in t ...

随机推荐

  1. RabbitMQ使用教程(一)RabbitMQ环境安装配置及Hello World示例

    你是否听说过或者使用过队列? 你是否听说过或者使用过消息队列? 你是否听说过或者使用过RabbitMQ? 提到这几个词,用过的人,也许觉得很简单,没用过的人,也许觉得很复杂,至少在我没使用消息队列之前 ...

  2. 物体检测丨从R-CNN到Mask R-CNN

    这篇blog是我刚入目标检测方向,导师发给我的文献导读,深入浅出总结了object detection two-stage流派Faster R-CNN的发展史,读起来非常有趣.我一直想翻译这篇博客,在 ...

  3. sqlserver 数据库 的数据库个数统计 表个数统计 表的数据量统计(转载)

    http://www.cnblogs.com/qinche/archive/2012/08/09/app.html 由于今天要监控数据,急需统计实例中1有多少库2库里有多少表3每个表有多少数据 --将 ...

  4. 巧用伪元素绘制带边的三角形--CSS3

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  5. 20170405JDBC数据查询

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  6. JavaBean+jsp开发模式 --结合form表单 实例

    1.创建form表单 <%@ page language="java" contentType="text/html; charset=UTF-8" pa ...

  7. 变更gcc版本

    当前的GCC版本为GCC-4.2,需要切换到GCC-3.4.首先,你需要去你的usr/bin/下去看看有没有gcc-3.4这样文件,如果没有的话,就安装一下吧: apt-get install gcc ...

  8. CMSG_COMPAT_ALIGN函数

    CMSG_COMPAT_ALIGN函数是什么的使用方法?

  9. (五)我的JavaScript系列:JavaScript的糟粕

    泪眼问花花不语,乱红飞过秋千去. JavaScript的糟粕 JavaScript语言是一门集精华与糟粕于一体的语言.在JavaScript: the good parts中,便集中讨论了关于精华与糟 ...

  10. WisdomTool REST Client 下载 测试请求,生成api文档

    https://github.com/Wisdom-Projects/rest-client