背景
目前复习sql语言,在前几篇博客详细描述了sql的语法,但是在刷sqlzoo过程中遇到一些没有学习的知识点,在这篇博客进行总结。
之前的复习笔记,可以作为参考:https://blog.csdn.net/Foools/article/details/109248894
文章目录
一、round函数
ROUND 函数用于把数值字段舍入为指定的小数位数。decimals可以设置为负数。
SQL ROUND() 语法
SELECT ROUND(column_name,decimals) FROM table_name
例题
Show the name and population in millions and the GDP in billions for the countries of the continent ‘South America’. Use the ROUND function to show the values to two decimal places.
For South America show population in millions and GDP in billions both to 2 decimal places.
select name,round(population/1000000,2),round(gdp/1000000000,2) from world
where continent='South America'
二、left函数
You can use the function LEFT to isolate the first character.本质上是一个截断操作,string类型的数据,进行从左端开始截取。
例题
Show the name and the capital where the first letters of each match. Don’t include countries where the name and the capital are the same word.
SELECT name, capital
FROM world
where