MySQL小结_MySQL小结

1.Where in 的用法:

IN运算符允许您在WHERE子句中指定多个值。IN 操作符允许我们在 WHERE 子句中规定多个值。IN运算符是多个OR条件的简写。

SELECT "栏位名"

FROM "表格名"

WHERE "栏位名" IN('值一', '值二', ...)

#字符串用单引号标注,包括后面的应用like的模糊查询,like后面的字符串也要加引号。

#操作符 BETWEEN ... AND 会选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。

z.B Show all details of the presidential winners:Theodore Roosevelt

Woodrow Wilson

Jimmy Carter

Barack Obama

SELECT *

FROM nobel

WHERE winner IN ('Theodore Roosevelt',

'Woodrow Wilson',

'Jimmy Carter','Barack Obama')

2.ROUND 用法

z.BShow thenameandpopulationin millions and the GDP in billions for the countries of thecontinent'South America'. Use the ROUND function to show the values to two decimal places.

select name,round(population/1000000,2),round(gdp/1000000000,2)

from world

where continent='South America'

####ROUND函数,有2个参数

ROUND(你需要修改的数字,保留的小数点位数)

默认是不显示小数点,正数是保留的小数点的位数

负数是向左进行保留

比如

ROUND(10/3,2)=3.33

ROUND(10/3)=3

ROUND(12345,-2)=12300

3.Length 的用法

z.BGreece has capital Athens.Each of the strings 'Greece', and 'Athens' has 6 characters.

Show the name and capital where the name and the capital have the same number of characters.You can use the LENGTH function to find the number of characters in a string

SELECT name,capital

FROM world

WHERE length(name)=length(capital)

4.Matching name and capital 以及<>‘不等同’的引用

The capital of Sweden is Stockholm. Both words start with the letter 'S'.

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.You can use the function LEFT to isolate the first character.

You can use <> as the NOT EQUALS operator.

select name, capital

from world

where left(name,1)=left(capital,1) and name<>capital;

5.Like--模糊查询的应用

Equatorial Guinea and Dominican Republic have all of the vowels (a e i o u) in the name. They don't count because they have more than one word in the name.

Find the country that has all the vowels and no spaces in its name.You can use the phrase name NOT LIKE '%a%' to exclude characters from your results.

The query shown misses countries like Bahamas and Belarus because they contain at least one 'a'

###like 后面要模糊查找的字符串要加引号。

select name

from world

where name like '%a%'

and name like'%e%'

and name like '%i%'

and name like'%o%'

and name like '%u%'

and name not like '% %'

6.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值