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
-- 要点:as设置别名,as可省略
select first_name as "First Name", last_name as "Last Name"
from employees

  

2. Write a query to get unique department ID from employee table
Sample table: employees
-- 要点:select时添加distinct获取唯一值
select distinct department_id
from employees
3. Write a query to get all employee details from the employee table order by first name, descending
Sample table: employees
-- 要点:order by进行排序,desc进行降序排序
select *
from employees
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
-- 要点:select中可以进行数学运算
select first_name, last_name, salary, salary*0.15 as PF
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
-- 要点:order by + asc
select employee_id, first_name, last_name, salary
from employees
order by salary asc

  

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

  

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

  

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

  

12. Write a query to get the first 3 characters of first name from employees table
Sample table: employees
-- 要点:left()从左开始取字符
select left(first_name, 3)
from employees
13. Write a query to calculate 171*214+625
-- 要点:select可直接计算
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
-- 要点:concat()两列字符串组合
select concat(first_name, ' ', last_name)
from employees

  

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

  

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

  

18. Write a query to select first 10 records from a table
Sample table: employees
-- 要点:limit限制取数量
select *
from employees
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
-- 要点:round()实现小数位控制
select first_name, last_name, round(salary/12, 2) as 'Monthly Salary'
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. JavaScript基础学习日志(1)——属性操作

    JS中的属性操作: 属性操作语法 属性读操作:获取 实例:获取Input值 实例:获取select值 字符串连接 属性写操作:修改.添加 实例:修改value值 实例:添加图片的src地址 inner ...

  2. Netty(3)Time protocol

    本节介绍TIME协议.该协议与前边的discard协议和echo协议的不同点在于:1.服务端主动发送消息给到客户端,所以需要channelActive()方法.2.发送的消息是4个字节的int3.不接 ...

  3. net core (下)

    net core (下) 第一部分: https://www.cnblogs.com/cgzl/p/8450179.html 本文是基于Windows10的. Debugging javascript ...

  4. 049 Group Anagrams 字谜分组

    给定一个字符串数组,将相同字谜组合在一起.(字谜是指颠倒字母顺序而成的字)例如,给定 ["eat", "tea", "tan", " ...

  5. javascript 关于hashtable

    javascript 实现HashTable(哈希表) 一.javascript哈希表简介 javascript里面是没有哈希表的,一直在java,C#中有时候用到了这一种数据结构,javascrip ...

  6. 7.Solution的Build、Rebuild和Clean

    大家好,我是原文,这篇随笔是对原文的翻译以及自己的体会. 做程序员没追求的话是永远找不到女朋友的,当然有追求也找不到,这个先不提,好在有追求的时候我是充实而且开心的.现在我们的问题是,每天调试项目,在 ...

  7. form-data、x-www-form-urlencoded、raw、binary的区别

    1.form-data: 就是http请求中的multipart/form-data,它会将表单的数据处理为一条消息,以标签为单元,用分隔符分开.既可以上传键值对,也可以上传文件.当上传的字段是文件时 ...

  8. freebsd新添加磁盘

    1.添加硬盘 2.查看现在的硬盘 3.执行sysinstall命令 4. 5. 6.按下enter键 7.A,C,Q 8. 9. 10.C,Q 11.newfs /dev/ad0 12.cd / &a ...

  9. 家校通Code

    9 http://dlwt.csdn.net/fd.php?i=621573845033702&s=44d46a459acce7fef39aa4dcff51bfba

  10. 单列表变量与字符串拆分的对照(SqlServer)

    最近遇到一个问题,在SQLServer中,需要根据用户传入的一系列ID值更新对应的记录.有两种方法,一种是将这些ID值使用逗号分隔,拼接成字符串传入,一种是以表变量的方式传入.最开始,我想当然的认为传 ...