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. org.apache.ibatis.binding.BindingException【原因汇总】

    这个问题整整纠结了我四个多小时,心好累啊...不废话... 背景:Spring整合Mybatis 报错:org.apache.ibatis.binding.BindingException: Inva ...

  2. JavaSE---jar文件

    1.当一个应用程序开发完成后,大致有3种方式发布: 1.1 使用平台相关的编译器将整个应用编译成平台相关的可执行文件: 1.2 为整个应用编辑一个批处理文件: 1.3 将应用程序制作为一个可执行的ja ...

  3. 使用cp命令拷贝目录下指定文件外的其他文件

    shopt -s extglob cp test/!(abc*) test2/ cp test目录下除了以abc开头的其他文件 如果是除去多个文件的话使用   !(a|b)   ;   注意不要多加空 ...

  4. mongodb 分片技术

    MongoDB Sharding Cluster 分片集群 规划:10个实例:38017-38026 (1)configserver:3台构成的复制集(1主两从,不支持arbiter)38018-38 ...

  5. LWIP应用指南学习。

    一 TCP接口函数:tcp_init() 必须在调用其它TCP函数之前调用,必须用一个硬件定时器来配置每TCP_FAST_INTERVAL (ms)调用一次tcp_fasttmr() :每TCP_SL ...

  6. 洪水(flood)

    洪水(flood) 题目背景 Awson是某国际学校信竞组的一只菜鸡.今年,该市发生了千年难遇的洪水.被监禁在学校的Awson不甘怠堕,想将自己投入到公益服务事业中去.这天,他偷了H老师的小电驴,偷偷 ...

  7. 洛谷-P3927 SAC E#1 - 一道中档题 Factorial

    原址 题目背景 数据已修改 SOL君(炉石主播)和SOL菌(完美信息教室讲师)是好朋友. 题目描述 SOL君很喜欢阶乘.而SOL菌很喜欢研究进制. 这一天,SOL君跟SOL菌炫技,随口算出了n的阶乘. ...

  8. zuul忽略表达式

    如果有error过滤器,会进入error

  9. window.open()弹出窗口参数说明及居中设置

    window.open()可以弹出一个新的窗口,并且通过参数控制窗口的各项属性. 最基本的弹出窗口代码 window.open('httP://codeo.cn/'); window.open()各参 ...

  10. SQLServer 2012 Always on配置全过程

    AlwaysOn取数据库镜像和故障转移集群之长.AlwaysOn不再像故障转移集群那样需要共享磁盘,从而主副本和辅助副本可以更容易的部署到不同的地理位置:AlwaysOn还打破了镜像只能1对1的限制, ...