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. hdu5726-GCD-ST表+二分

    先用st表处理出所有l-r的GCD值,然后二分求得这些值一共出现了多少次. #include<bits/stdc++.h> #define inf 0x3f3f3f3f ; using n ...

  2. php:比较两个txt文件,格式如下,分别取出a.txt有的b.txt没有的,b.txt有的a.txt没有的及两个都有的

    <?php /*比较两个txt文件,格式如下,分别取出a.txt有的b.txt没有的,b.txt有的a.txt没有的及两个都有的 * a.txt: * A * B * C * D * b.txt ...

  3. java Integer

    Java 中的数据类型分为基本数据类型和引用数据类型 int是基本数据类型,Integer是引用数据类型: Ingeter是int的包装类,int的初值为0,Ingeter的初值为null. 初始化 ...

  4. hard link && symbolic link

    hard link :硬连接,多了一个inode,指向原始的inode,通过这个硬连接删除文件,文件不会被真正删除,而是删除这个inode symolic link:符号连接相当于快捷方式

  5. css position 定位模式

     定位 定位模式: static relative absolute fixed 边偏移 :top bottom left right 一般的定位必须要有定位模式以及边偏移 static 静态定位 默 ...

  6. ABAP事件分类

    1.报表事件 INITIALIZATION. START-OF-SELECTION. END-OF-SELECTION. 2.选择屏幕事件 在INITIALIZATION和START-OF-SELEC ...

  7. Android 使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突

    如果你还在为处理滑动冲突而发愁,那么你需要静下心来看看这边文章,如果你能彻底理解这篇文章中使用的技术,那么,一切滑动冲突的问题解决起来就轻而易举了: 先扔一个最终实现的效果图 先分析下效果图中实现的功 ...

  8. Python+selenium之调用JavaScript

    webdriver提供了操作浏览器的前进和后退的方法,但是对于浏览器公东条并没有提供相应的操作方法.于是就需要借助JavaScript来控制浏览器的滚动条.webdriver提供了execute_sr ...

  9. img标签src资源无法加载,报net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION错

    html代码: chrome和360浏览器均报错,系统自带IE.Firefox浏览器没有问题 原因:加载的资源名含有半角逗号(,)或者别的特殊符号 解决办法:后台给资源名加上双引号("&qu ...

  10. Java 文件操作-RandomAccessFile

    1. RandomAccessFile     Java提供了一个可以对文件随机访问的操作,访问包括读和写操作.该类名为RandomAccessFile.该类的读写是基于指针的操作. 1)文件访问模式 ...