plsql developer设置查询结果显示列注释_SQL简单查询

本文介绍了在PL/SQL Developer中如何设置查询结果显示列注释,并提供了多个SQL查询实战题目,涵盖别名设置、去重、查询顺序、注释、空值处理、字符串操作等基础概念,帮助读者巩固SQL查询技能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自测题:

1.从student表中查询姓名和性别,并且姓名改成别名name, 性别改成别名男或女

2.如何删除重复值?例如如何只显示姓名的唯一值?如何显示姓名和学号的唯一值?

3.运行顺序是怎样的?select 姓名,成绩 from student where 姓名='猴子';

4.单行注释方法以及多行注释方法

5.5+Null等于什么

6.显示world表中的国家,人口,gdp和人均gdp

7.为什么查询结果会出现10<2?如何解决?

8.如何查询出空值?如何查询出非空值

例如从student中查询姓名和成绩,查询出的成绩为空值;查询出的成绩不为空值。

9.如何查询以猴开头的名字、以猴结尾的名字、包含猴的名字、以猴开头的三个字的名字、以猴开头的两个字的名字

10.查询姓名为猴子马云的姓名和成绩(两种写法)

11.查找出性别是男并且姓名是猴子或者马云的人名和成绩

12.查找出成绩大于等于60,小于等于90的学生(两种写法)

13.查询面积大的国家或者人口多的国家,但是不能同时是面积大且人口多。

面积大的定义:more than 3 million ,人口多的定义:more than 250 million

显示国家名字,人口,面积。

14.如何对小数点后的位数进行四舍五入

查询'South America' 中的国家,人口以百万的形式显示,gdp以十亿的形式显示

并且对显示的值进行四舍五入,保留小数点后两位。

(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.Divide by 1000000 (6 zeros) for millions. Divide by 1000000000 (9 zeros) for billions.)

15.如何对千位进行四舍五入

Show the name and per-capita GDP for those countries with a GDP of at least one trillion (1000000000000; that is 12 zeros). Round this value to the nearest 1000.

Show per-capita GDP for the trillion dollar countries to the nearest $1000.

16.如何计算字符数

Show the name and capital where the name and the capital have the same number of characters.

17.如何将字符串的首个字符提取出来

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.


自测题答案:

1.从student表中查询姓名和性别,并且姓名改成别名name, 性别改成别名男或女

改成别名用as

select 姓名 as name,性别 as '男或女' from student;

2.如何删除重复值?例如如何只显示姓名的唯一值?如何显示姓名和学号的唯一值?

删除重复值可通过在列名前加distinct。若是两个列名组成的唯一值,只能在第一个列名前加distinct.

select distinct 姓名 from student;

Select distinct 姓名,学号 from students;

3.运行顺序是怎样的?select 姓名,成绩 from student where 姓名='猴子';

select子句最后运行,其他子句的运行顺序按照书写顺序进行运行

From student :找到student这个表

Where 姓名='猴子':在这个表中把姓名叫猴子的行全部找出来

Select 姓名,成绩 :在这些姓名叫猴子的行中,只显示出姓名列和姓名对应的成绩列

4.单行注释方法以及多行注释方法

-- select * from student; (单行注释)

/* select * from student;

Select * from teacher; */

5.5+Null等于什么

5+Null=Null

所有含有空值的运算,结果为空值

6.显示world表中的国家,人口,gdp和人均gdp

select name, population, gdp, gdp/population from world

7.为什么查询结果会出现10<2?如何解决?

可能原因是,数据类型设置成了字符串类型而非数值类型

10这个字符串是以1字符串开头,1字符串小于2, 所以会返回10<2

比较运算符可以和所有类型的值进行比较

8.如何查询出空值?如何查询出非空值?

Is null/is not null

例如从student中查询姓名和成绩,查询出的成绩为空值;查询出的成绩不为空值。

select 姓名,成绩 from student where 成绩 is null;

select 姓名,成绩 from student where 成绩 is not null;

9.如何查询以猴开头的名字、以猴结尾的名字、包含猴的名字、以猴开头的三个字的名字、以猴开头的两个字的名字

%可代表任意个数的字符

_ 仅可代表1个字符

like表示模糊查询

select 姓名 from student where 姓名 like '猴%';

select 姓名 from student where 姓名 like '%猴';

select 姓名 from student where 姓名 like '%猴%';

select 姓名 from student where 姓名 like '猴__';

select 姓名 from student where 姓名 like '猴_';

10.查询姓名为猴子或马云的姓名和成绩(两种写法)

select 姓名,成绩 from student where 姓名 = '猴子' or 姓名 = '马云';

select 姓名,成绩 from student where 姓名 in ('猴子','马云');

11.查找出性别是男并且姓名是猴子或者马云的人名和成绩

() 括号扩起来的是优先运算

Select 姓名,成绩 from student

Where 性别='男' and (姓名='猴子' or 姓名='马云');

12.查找出成绩大于等于60,小于等于90的学生 (两种写法)

Between....and 包括两边的边界值

Select 姓名,成绩 from student where 成绩 >= 60 and 成绩<= 90;

Select 姓名,成绩 from student where 成绩 between 60 and 90;

13.查询面积大的国家或者人口多的国家,但是不能同时是面积大且人口多。

面积大的定义:more than 3 million, 人口多的定义:(more than 250 million

显示国家名字,人口,面积。

Not 对条件进行否定

Select name, population, area from world

where (area > 3000000 or population >250000000)

and not (area > 3000000 and population >250000000);

14.如何对小数点后的位数进行四舍五入

用round函数

查询'South America' 中的国家,人口以百万的形式显示,gdp以十亿的形式显示

并且对显示的值进行四舍五入,保留小数点后两位。

(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.Divide by 1000000 (6 zeros) for millions. Divide by 1000000000 (9 zeros) for billions.)

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

from world

where continent='South America' ;

15.如何对千位进行四舍五入

用round函数,第二参数大于0是对小数点后的位数进行四舍五入,第二参数小于0是对小数点前的位数进行四舍五入

Show the name and per-capita GDP for those countries with a GDP of at least one trillion (1000000000000; that is 12 zeros). Round this value to the nearest 1000.

Show per-capita GDP for the trillion dollar countries to the nearest $1000.

Select name, round(gdp/population, -3)

from world

where gdp >=1000000000000;

16.如何计算字符数

用Length函数

Show the name and capital where the name and the capital have the same number of characters.

Select name, capital

from world

where length(name)=length(capital);

17.如何将字符串的首个字符提取出来

用left函数

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 left(name,1)=left(capital,1)

and name<>capital;


sqlzoo题目的截图

a8f88576b9bfef9052ab103b92f44d47.png

6b343476c6b2e6058f5b3720541ba55b.png

9ef715126574deeaa6cbc991e269656f.png

d47d6d8260ca639e67f7c4153bd37d8a.png

071d9837005d3ee0f54254d00f2d4690.png

b298e122451c37897d5f073ceb60530f.png

ed3889cb2675daa492af04f79c10a809.png

abef04a58b85d2e3bd61f21949a8e9ae.png

83ec5d3b91041962aeb61726ce31fb02.png

9f03b0885f92f63b48b8349bb2182ad8.png

baa8442bd3d127f7bf593dd6b29bec81.png

56d1dc22dd2372fdc3fe464c9eb81953.png

f9f66f3eb3c159278c48b18fb9bd99e2.png

f9f66f3eb3c159278c48b18fb9bd99e2.png

f031f62a65d54832e9db7b82b1fa36f8.png

c7a937baa96754dc22326251f0060a75.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值