- 浏览: 15583 次
- 性别:
- 来自: 青岛
-
文章分类
最新评论
一、动态的增删改列,用alter(更改)
alter table class add rq_open datetime;
alter table class drop column rq_open;
alter table class alter column rq_open int;
*******二、速记公式
iiv insert into 表 values
dfw delete from 表 where
usw update 表 set where
sfwo select from 表 where order
sfwo+gh select from 表 where 条件 排序方式 group by 字段 having 条件 order by 字段
注:
sfw+gh+o order by 排在最后
********用round函数取整
round(--,0)
*******用最简单的数据来模拟业务工作环境
二、insert into
如果只要值不要键,那么值必须与表中一一对应且完整
三、字符串和日期要用单引号
getdate()获取当前日期
查询系统日期:select getdate()
面试题:从JVM和DB中获取的日期有什么不同?
JVM和DB有可能不在同一计算机中,当然要以数据操作的时间为准
所以,工作中取系统时间是从数据库中取!
四、增删改过程中,数据库的定位原理
delete from stu where sid=3
sid相当于一个变量,对每条记录的值进行一一比较,返回一个布尔值
1=3 false
2=3 false
3=3 true
例:delete from stu where 3=3 数据库查询每一条都返回true,所以会删除所有记录
五、三种删除
1、delete记录时,DB会做几件事?
删除记录、删除索引、写日志
2、所以删除大量记录时,用delete很慢
那么就用truncate table t1
truncate只能删除全部记录,只删除记录,不删除表。DB只做删除一件事,所以快
3、三种场合
delete:删除部分记录(条件删除),写日志和索引
truncate table t1:删除全部记录,不写日志和索引
drop table t1:连表也一起删除
六、select*from class
*代表所有字段,在执行前DB会找到该表的所有字段(内部操作)
只选择关心的字段------这个叫“投影”,效率高得多
select sid,sname,sex from stu
实际中很少用*,都用投影
七、字段别名[as](通常是在查询的时候使用,表的源数据不会改变)
例:1、select sid,sname,age,age+1 as 明年年龄 from stu;
2、select sid,sname,age,'lovo' as 学校 from stu;
八、可以用变量和常量来类比,数据库中的变量名和字符串
九、计算列
可以写字段的运算表达式,这个叫计算列
例1、select 商品数量,单价,商品数量*单价 as 总价 from 消费表
例2、select 商品数量,单价,单价*0.8 as 打折价 from 消费表 where 打折标记=1;
好处之一:原价变了之后,打折价会随之变化
计算列:将字段的值进行计算,并返回计算结果,有几条记录,就计算几次
十、select 'x' from class
对于每一行记录,都返回'x'
可以类比select sid from class 来理解 返回每一条变量sid的值,而'x'相当于常量
用返回值来理解
十一、复制表(没有复制表的约束,只有表的结构和数据)
select * into kk from class;
kk是新建的,原则复制不成功
思考:如何只得到一个空的表结构?(不要数据)
select * into kk from class where 2=3;
也就是每一行记录都返回false,表结构into了但记录不会into
十二、定义表别名
select * from stu s;
select * from stu as s; 千万别用as,因为在oracle中不支持as
select s.* from stu s;
表别名在多表查询中才有用
例:
十三、可以为字段定义别名,也可以为表定义别名
十四、条件查询
select * from stu where age >= 20 and cid=1 and sex='女'
select * from stu where age >=20 or ( cid=1 and score >40)
select * from stu where age between 18 and 22;between包括等号
select * from stu where cid in(2,3,4);in与or 的意思相同
十五、模糊查询
_ _ %只能和like匹配
_:一个字符,不管汉字或字母
%:0到多个字符
select * from stu where sname like '张%';匹配张字开头的
select * from stu where sname like '%张%';匹配有张字的
select * from stu where sname like '张_'
select * from stu where sname like '_ _';匹配两个字符
十六、获取字符串的长度
len()方法中可以是常量字符串也可以使字符串变量
select len('mike'),select len('我你他好'),返回4
select * from stu where len(sname)=4;返回sname的长度为4的记录
十七、判断和比较的区别
select * from stu where age = null;等号是比较
select * fromstu where age is null;is 和not is是判断
null只能用判断而不能用比较
十八、控制转化函数(不考试,显示为0)
字段不插入,默认为null
select sid,sname,score,isnull(score , 0) as new_score from stu;
显示一列new_score,如果score为null则显示0,不为空则显示score
类比三元运算符
十九、排序
select sid,sname,score from stu order by score asc; 默认为asc升序
desc降序
多字段排序
select sid,sname,score from stu order by score asc;
select sid,sname,score,from stu order by score,sid desc;
先按照score升序排列,相同的字段再按照sid降序排列
思考:如何实现不用desc降序
order by -score;
负值排序
********************************************************************、
1、关于group by表内容:
2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
如果要生成下列结果, 该如何写sql语句?
胜 负
2005-05-09 2 2
2005-05-10 1 2
答案:
1) select rq,sum(case when shengfu='胜' then 1 else 0 end) as胜,sum(case when shengfu='负' then 1 else 0 end) as负from tab3 group by rq
2) select N.rq,N. 胜,M. 负 from
(select rq,count(*) 胜 from tab3 where shengfu='胜'group by rq)N inner join
(select rq,count(*) 负from tab3 where shengfu='负'group by rq)M on N.rq=M.rq
3) select a.rq,a. 胜 as胜,b.负 as 负from
(select rq,count(shengfu) 胜from tab3 where shengfu='胜' group by rq) a,
(select rq,count(shengfu) 负from tab3 where shengfu='负' group by rq) b
where a.rq=b.rq;
1.关于group by表内容:
2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
如果要生成下列结果, 该如何写sql语句?
胜 负
2005-05-09 2 2
2005-05-10 1 2
--------------------------------------------------------------------------------------------
1) select rq,sum(case when shengfu='胜' then 1 else 0 end) as胜,sum(case when shengfu='负' then 1 else 0 end) as负from tab3 group by rq
2) select N.rq,N. 胜,M. 负 from
(select rq,count(*) 胜 from tab3 where shengfu='胜'group by rq)N inner join
(select rq,count(*) 负from tab3 where shengfu='负'group by rq)M on N.rq=M.rq
3) select a.rq,a. 胜 as胜,b.负 as 负from
(select rq,count(shengfu) 胜from tab3 where shengfu='胜' group by rq) a,
(select rq,count(shengfu) 负from tab3 where shengfu='负' group by rq) b
where a.rq=b.rq;
2.表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
--------------------------------------------------------------------------------------------
select (case when a>b then a else b end),(case when b>c then b else c end) from tab4
3.一个日期判断的sql语句
请取出tab5表中日期(SendTime字段)为当天的所有记录?(SendTime字段为datetime型,包含日期与时间)
---------------------------------------------------------------------------------------------
select * from tab5 t where to_char(t.SendTime,'yyyy-mm-dd')=to_char(sysdate,'yyyy-mm-dd')
4.有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。
显示格式:
语文 数学 英语
及格 优秀 不及格
-------------------------------------------------------------------------------------------
select
(case when语文>=80 then '优秀' when语文>60 then '及格' else '不及格' end) as 语文,
(case when 数学>=80 then '优秀' when数学>60 then '及格' else '不及格' end) as数学,
(case when英语>=80 then '优秀' when英语>60 then '及格' else '不及格' end) as 英语
from tab5
5.请用一个sql语句得出结果
从table1,table2中取出如table3所列格式数据
table1
月份mon 部门dep 业绩yj
-------------------------------
一月份 01 10
一月份 02 10
一月份 03 5
二月份 02 8
二月份 04 9
三月份 03 8
table2
部门dep 部门名称depname
--------------------------------
01 国内业务一部
02 国内业务二部
03 国内业务三部
04 国际业务部
table3 (result)
部门dep 一月份 二月份 三月份
---------------------------------------------------
01 10 null null
02 10 8 null
03 5 null 8
04 null 9 null
-------------------------------------------------------------------------------------------
1)
select t.depname,
(select yj from tab6 where mon='一月份' and dep=t.dep) 一月份,
(select yj from tab6 where mon='二月份' and dep=t.dep) 二月份,
(select yj from tab6 where mon='三月份' and dep=t.dep) 三月份
from tab7 t
---------------------------------------------------------
2)求总销售额
select
sum(case when t1.mon='一月份' then t1.yj else 0 end) 一月份,
sum(case when t1.mon='二月份' then t1.yj else 0 end) 二月份,
sum(case when t1.mon='三月份' then t1.yj else 0 end) 三月份
from tab7 t,tab6 t1 where t.dep=t1.dep
6.一个表中的Id有多个记录,把所有这个id的记录查出来,并显示共有多少条记录数。
-------------------------------------------------------------------------------
select id,count(*) from tab8 group by id having count(*)>1
select * from (select tab8,count(id) as num from tab8 group by id) t where t.num>1
7.用一条SQL语句 查询出每门课都大于80分的学生姓名
name kecheng fenshu
张三 语文 81
张三 数学 75
李四 语文 76
李四 数学 90
王五 语文 81
王五 数学 100
王五 英语 90
a): select distinct name from tab9 where name not in (select distinct name from tab9 where fengshu<=80)
b): select * from tab9 t7 where t7.name not in (select t5.name from (select * from (select t1.kecheng from tab9 t1 group by t1.kecheng),(select t2.name from tab9 t2 group by t2.name)) t4,(select * from tab9) t5 where t4.name = t5.name and t4.kecheng = t5.kecheng and t5.fengshu < 80)
8.一个叫department的表,里面只有一个字段name,一共有4条纪录,分别是a,b,c,d,对应四个球对,现在四个球对进行比赛,用一条sql语句显示所有可能的比赛组合.
select t.bh||'vs'||t1.bh from tab10 t,tab10 t1 where t.bh<>t1.bh这个是分主客场的
select t.bh||'vs'||t1.bh from tab10 t,tab10 t1 where t.bh<>t1.bh and t.bh>t1.bh这个是不分的
9.怎么把这样一个表儿
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
查成这样一个结果
year m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4
a):
select t.year,
(select a.amout from tab11 a where a.month=1 and a.year=t.year) m1,
(select b.amout from tab11 b where b.month=2 and b.year=t.year) m2,
(select c.amout from tab11 c where c.month=3 and c.year=t.year) m3,
(select d.amout from tab11 d where d.month=4 and d.year=t.year) m4
from tab11 t group by t.year
10.拷贝表(拷贝数据,源表名:a 目标表名:b)
SQL: insert into b(a, b, c) select d,e,f from b;
create table test as select * from dept; --从已知表复制数据和结构
create table test as select * from dept where 1=2; --从已知表复制结构但不包括数据
11.显示文章、提交人和最后回复时间
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
12.日程安排提前五分钟提醒
13.两张关联表,删除主表中已经在副表中没有的信息
delete from fubiao a where a.fid not in(select id from zhubiao)
14.有两个表tab12和tab13,均有key和value两个字段,如果tab13的key在tab12中也有,就把tab13的value换为tab12中对应的value
update tab13 set value=(select value from tab12 where tab12.key=tab13.key)
15.原表:
courseid coursename score
-------------------------------------
1 java 70
2 oracle 90
3 xml 40
4 jsp 30
5 servlet 80
-------------------------------------
为了便于阅读,查询此表后的结果显式如下(及格分数为60):
courseid coursename score mark
---------------------------------------------------
1 java 70 pass
2 oracle 90 pass
3 xml 40 fail
4 jsp 30 fail
5 servlet 80 pass
---------------------------------------------------
select t.courseid,t.coursename,t.score,(case when score>60 then 'pass' else 'fail' end) mark from tab14 t
16.表15
a1 a2
1 a
1 b
2 x
2 y
2 z
用select能选成以下结果吗?
1 ab
2 xyz
17.题为
有两个表, t1, t2,
Table t1:
SELLER | NON_SELLER
----- -----
A B
A C
A D
B A
B C
B D
C A
C B
C D
D A
D B
D C
Table t2:
SELLER | BAL
------ --------
A 100
B 200
C 300
D 400
要求用SELECT 语句列出如下结果:------如A的SUM(BAL)为B,C,D的和,B的SUM(BAL)为A,C,D的和.......
且用的方法不要增加数据库负担,如用临时表等
alter table class add rq_open datetime;
alter table class drop column rq_open;
alter table class alter column rq_open int;
*******二、速记公式
iiv insert into 表 values
dfw delete from 表 where
usw update 表 set where
sfwo select from 表 where order
sfwo+gh select from 表 where 条件 排序方式 group by 字段 having 条件 order by 字段
注:
sfw+gh+o order by 排在最后
********用round函数取整
round(--,0)
*******用最简单的数据来模拟业务工作环境
二、insert into
如果只要值不要键,那么值必须与表中一一对应且完整
三、字符串和日期要用单引号
getdate()获取当前日期
查询系统日期:select getdate()
面试题:从JVM和DB中获取的日期有什么不同?
JVM和DB有可能不在同一计算机中,当然要以数据操作的时间为准
所以,工作中取系统时间是从数据库中取!
四、增删改过程中,数据库的定位原理
delete from stu where sid=3
sid相当于一个变量,对每条记录的值进行一一比较,返回一个布尔值
1=3 false
2=3 false
3=3 true
例:delete from stu where 3=3 数据库查询每一条都返回true,所以会删除所有记录
五、三种删除
1、delete记录时,DB会做几件事?
删除记录、删除索引、写日志
2、所以删除大量记录时,用delete很慢
那么就用truncate table t1
truncate只能删除全部记录,只删除记录,不删除表。DB只做删除一件事,所以快
3、三种场合
delete:删除部分记录(条件删除),写日志和索引
truncate table t1:删除全部记录,不写日志和索引
drop table t1:连表也一起删除
六、select*from class
*代表所有字段,在执行前DB会找到该表的所有字段(内部操作)
只选择关心的字段------这个叫“投影”,效率高得多
select sid,sname,sex from stu
实际中很少用*,都用投影
七、字段别名[as](通常是在查询的时候使用,表的源数据不会改变)
例:1、select sid,sname,age,age+1 as 明年年龄 from stu;
2、select sid,sname,age,'lovo' as 学校 from stu;
八、可以用变量和常量来类比,数据库中的变量名和字符串
九、计算列
可以写字段的运算表达式,这个叫计算列
例1、select 商品数量,单价,商品数量*单价 as 总价 from 消费表
例2、select 商品数量,单价,单价*0.8 as 打折价 from 消费表 where 打折标记=1;
好处之一:原价变了之后,打折价会随之变化
计算列:将字段的值进行计算,并返回计算结果,有几条记录,就计算几次
十、select 'x' from class
对于每一行记录,都返回'x'
可以类比select sid from class 来理解 返回每一条变量sid的值,而'x'相当于常量
用返回值来理解
十一、复制表(没有复制表的约束,只有表的结构和数据)
select * into kk from class;
kk是新建的,原则复制不成功
思考:如何只得到一个空的表结构?(不要数据)
select * into kk from class where 2=3;
也就是每一行记录都返回false,表结构into了但记录不会into
十二、定义表别名
select * from stu s;
select * from stu as s; 千万别用as,因为在oracle中不支持as
select s.* from stu s;
表别名在多表查询中才有用
例:
十三、可以为字段定义别名,也可以为表定义别名
十四、条件查询
select * from stu where age >= 20 and cid=1 and sex='女'
select * from stu where age >=20 or ( cid=1 and score >40)
select * from stu where age between 18 and 22;between包括等号
select * from stu where cid in(2,3,4);in与or 的意思相同
十五、模糊查询
_ _ %只能和like匹配
_:一个字符,不管汉字或字母
%:0到多个字符
select * from stu where sname like '张%';匹配张字开头的
select * from stu where sname like '%张%';匹配有张字的
select * from stu where sname like '张_'
select * from stu where sname like '_ _';匹配两个字符
十六、获取字符串的长度
len()方法中可以是常量字符串也可以使字符串变量
select len('mike'),select len('我你他好'),返回4
select * from stu where len(sname)=4;返回sname的长度为4的记录
十七、判断和比较的区别
select * from stu where age = null;等号是比较
select * fromstu where age is null;is 和not is是判断
null只能用判断而不能用比较
十八、控制转化函数(不考试,显示为0)
字段不插入,默认为null
select sid,sname,score,isnull(score , 0) as new_score from stu;
显示一列new_score,如果score为null则显示0,不为空则显示score
类比三元运算符
十九、排序
select sid,sname,score from stu order by score asc; 默认为asc升序
desc降序
多字段排序
select sid,sname,score from stu order by score asc;
select sid,sname,score,from stu order by score,sid desc;
先按照score升序排列,相同的字段再按照sid降序排列
思考:如何实现不用desc降序
order by -score;
负值排序
********************************************************************、
1、关于group by表内容:
2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
如果要生成下列结果, 该如何写sql语句?
胜 负
2005-05-09 2 2
2005-05-10 1 2
答案:
1) select rq,sum(case when shengfu='胜' then 1 else 0 end) as胜,sum(case when shengfu='负' then 1 else 0 end) as负from tab3 group by rq
2) select N.rq,N. 胜,M. 负 from
(select rq,count(*) 胜 from tab3 where shengfu='胜'group by rq)N inner join
(select rq,count(*) 负from tab3 where shengfu='负'group by rq)M on N.rq=M.rq
3) select a.rq,a. 胜 as胜,b.负 as 负from
(select rq,count(shengfu) 胜from tab3 where shengfu='胜' group by rq) a,
(select rq,count(shengfu) 负from tab3 where shengfu='负' group by rq) b
where a.rq=b.rq;
1.关于group by表内容:
2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
如果要生成下列结果, 该如何写sql语句?
胜 负
2005-05-09 2 2
2005-05-10 1 2
--------------------------------------------------------------------------------------------
1) select rq,sum(case when shengfu='胜' then 1 else 0 end) as胜,sum(case when shengfu='负' then 1 else 0 end) as负from tab3 group by rq
2) select N.rq,N. 胜,M. 负 from
(select rq,count(*) 胜 from tab3 where shengfu='胜'group by rq)N inner join
(select rq,count(*) 负from tab3 where shengfu='负'group by rq)M on N.rq=M.rq
3) select a.rq,a. 胜 as胜,b.负 as 负from
(select rq,count(shengfu) 胜from tab3 where shengfu='胜' group by rq) a,
(select rq,count(shengfu) 负from tab3 where shengfu='负' group by rq) b
where a.rq=b.rq;
2.表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
--------------------------------------------------------------------------------------------
select (case when a>b then a else b end),(case when b>c then b else c end) from tab4
3.一个日期判断的sql语句
请取出tab5表中日期(SendTime字段)为当天的所有记录?(SendTime字段为datetime型,包含日期与时间)
---------------------------------------------------------------------------------------------
select * from tab5 t where to_char(t.SendTime,'yyyy-mm-dd')=to_char(sysdate,'yyyy-mm-dd')
4.有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。
显示格式:
语文 数学 英语
及格 优秀 不及格
-------------------------------------------------------------------------------------------
select
(case when语文>=80 then '优秀' when语文>60 then '及格' else '不及格' end) as 语文,
(case when 数学>=80 then '优秀' when数学>60 then '及格' else '不及格' end) as数学,
(case when英语>=80 then '优秀' when英语>60 then '及格' else '不及格' end) as 英语
from tab5
5.请用一个sql语句得出结果
从table1,table2中取出如table3所列格式数据
table1
月份mon 部门dep 业绩yj
-------------------------------
一月份 01 10
一月份 02 10
一月份 03 5
二月份 02 8
二月份 04 9
三月份 03 8
table2
部门dep 部门名称depname
--------------------------------
01 国内业务一部
02 国内业务二部
03 国内业务三部
04 国际业务部
table3 (result)
部门dep 一月份 二月份 三月份
---------------------------------------------------
01 10 null null
02 10 8 null
03 5 null 8
04 null 9 null
-------------------------------------------------------------------------------------------
1)
select t.depname,
(select yj from tab6 where mon='一月份' and dep=t.dep) 一月份,
(select yj from tab6 where mon='二月份' and dep=t.dep) 二月份,
(select yj from tab6 where mon='三月份' and dep=t.dep) 三月份
from tab7 t
---------------------------------------------------------
2)求总销售额
select
sum(case when t1.mon='一月份' then t1.yj else 0 end) 一月份,
sum(case when t1.mon='二月份' then t1.yj else 0 end) 二月份,
sum(case when t1.mon='三月份' then t1.yj else 0 end) 三月份
from tab7 t,tab6 t1 where t.dep=t1.dep
6.一个表中的Id有多个记录,把所有这个id的记录查出来,并显示共有多少条记录数。
-------------------------------------------------------------------------------
select id,count(*) from tab8 group by id having count(*)>1
select * from (select tab8,count(id) as num from tab8 group by id) t where t.num>1
7.用一条SQL语句 查询出每门课都大于80分的学生姓名
name kecheng fenshu
张三 语文 81
张三 数学 75
李四 语文 76
李四 数学 90
王五 语文 81
王五 数学 100
王五 英语 90
a): select distinct name from tab9 where name not in (select distinct name from tab9 where fengshu<=80)
b): select * from tab9 t7 where t7.name not in (select t5.name from (select * from (select t1.kecheng from tab9 t1 group by t1.kecheng),(select t2.name from tab9 t2 group by t2.name)) t4,(select * from tab9) t5 where t4.name = t5.name and t4.kecheng = t5.kecheng and t5.fengshu < 80)
8.一个叫department的表,里面只有一个字段name,一共有4条纪录,分别是a,b,c,d,对应四个球对,现在四个球对进行比赛,用一条sql语句显示所有可能的比赛组合.
select t.bh||'vs'||t1.bh from tab10 t,tab10 t1 where t.bh<>t1.bh这个是分主客场的
select t.bh||'vs'||t1.bh from tab10 t,tab10 t1 where t.bh<>t1.bh and t.bh>t1.bh这个是不分的
9.怎么把这样一个表儿
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
查成这样一个结果
year m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4
a):
select t.year,
(select a.amout from tab11 a where a.month=1 and a.year=t.year) m1,
(select b.amout from tab11 b where b.month=2 and b.year=t.year) m2,
(select c.amout from tab11 c where c.month=3 and c.year=t.year) m3,
(select d.amout from tab11 d where d.month=4 and d.year=t.year) m4
from tab11 t group by t.year
10.拷贝表(拷贝数据,源表名:a 目标表名:b)
SQL: insert into b(a, b, c) select d,e,f from b;
create table test as select * from dept; --从已知表复制数据和结构
create table test as select * from dept where 1=2; --从已知表复制结构但不包括数据
11.显示文章、提交人和最后回复时间
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
12.日程安排提前五分钟提醒
13.两张关联表,删除主表中已经在副表中没有的信息
delete from fubiao a where a.fid not in(select id from zhubiao)
14.有两个表tab12和tab13,均有key和value两个字段,如果tab13的key在tab12中也有,就把tab13的value换为tab12中对应的value
update tab13 set value=(select value from tab12 where tab12.key=tab13.key)
15.原表:
courseid coursename score
-------------------------------------
1 java 70
2 oracle 90
3 xml 40
4 jsp 30
5 servlet 80
-------------------------------------
为了便于阅读,查询此表后的结果显式如下(及格分数为60):
courseid coursename score mark
---------------------------------------------------
1 java 70 pass
2 oracle 90 pass
3 xml 40 fail
4 jsp 30 fail
5 servlet 80 pass
---------------------------------------------------
select t.courseid,t.coursename,t.score,(case when score>60 then 'pass' else 'fail' end) mark from tab14 t
16.表15
a1 a2
1 a
1 b
2 x
2 y
2 z
用select能选成以下结果吗?
1 ab
2 xyz
17.题为
有两个表, t1, t2,
Table t1:
SELLER | NON_SELLER
----- -----
A B
A C
A D
B A
B C
B D
C A
C B
C D
D A
D B
D C
Table t2:
SELLER | BAL
------ --------
A 100
B 200
C 300
D 400
要求用SELECT 语句列出如下结果:------如A的SUM(BAL)为B,C,D的和,B的SUM(BAL)为A,C,D的和.......
且用的方法不要增加数据库负担,如用临时表等
相关推荐
SQL语句是数据库操作的核心,它用于查询、插入、更新和删除数据,是任何数据库管理系统中的基础工具。在IT行业中,编写SQL语句是一项必备技能,但手动编写和调试SQL语句可能会耗费大量时间和精力,尤其在处理复杂...
本项目提供了一个Java源码工具,能够帮助用户便捷地将Oracle SQL语句转换为MySQL SQL语句。 Oracle SQL与MySQL SQL的主要差异在于以下几个方面: 1. **数据类型**:Oracle支持的数据类型如NUMBER、LONG、RAW等在...
在Java编程中,调试SQL语句是开发过程中的常见任务,尤其当面对复杂且冗长的查询时。为了提高效率并使SQL语句更易于理解和分析,格式化SQL语句显得尤为重要。标题提及的"Java打印漂亮的SQL语句(被格式化的SQL语句)...
sql语句sql语句sql语句sql语句sql语句
"hibernate执行原生sql语句" Hibernate 是一种流行的 ORM(Object-Relational Mapping)框架,用于将 Java 对象映射到关系数据库中。然而,在一些情况下,我们需要直接执行原生 SQL 语句,而不是使用 Hibernate 的...
本文将深入探讨如何在C#中自动生成SQL语句,以提高开发效率并减少手动编写SQL可能导致的错误。 一、Entity Framework与自动SQL生成 1. Entity Framework(EF)是微软提供的一个开源ORM(对象关系映射)框架,它...
### 完成超长SQL语句执行前拆分 #### 概述 在使用Visual Basic (简称VB)进行数据库操作时,可能会遇到因为SQL语句过长而导致无法正常执行的问题。这种情况下,即使该SQL语句可以在SQL Server的查询分析器中成功运行...
PB脚本中SQL语句写法与SQL中语句写法对照 PB脚本中SQL语句写法与SQL中语句写法对照是非常重要的知识点,因为PB脚本和SQL语言在写法和应用中有所不同。本文将对PB脚本中SQL语句写法和SQL中语句写法进行对比和分析。 ...
在实际开发中,有时我们需要了解LINQ查询是如何转换为SQL语句的,以便于调试和优化性能。以下将详细介绍几种查看LINQ生成SQL语句的方法。 1. **Debug.WriteLine()** 在使用LINQ查询时,可以利用`Debug.WriteLine()...
### 动态执行SQL语句在Oracle中的应用 #### 标题解读 “存储过程中怎么动态执行SQL语句”这一标题表明文章将介绍如何在Oracle数据库的存储过程中编写能够动态执行的SQL语句。动态SQL是指在运行时才能确定其具体内容...
SQL Server 动态 SQL 语句的用法 SQL Server 中的动态 SQL 语句是一种灵活的查询方式,它可以根据不同的情况生成不同的 SQL 语句。动态 SQL 语句可以用来实现复杂的业务逻辑,提高查询效率和灵活性。 普通 SQL ...
### Oracle监听执行SQL语句详解 #### 一、Oracle监听执行概述 在Oracle数据库管理与维护过程中,有时候我们需要了解应用程序正在执行哪些SQL语句,这不仅有助于性能优化,还可以帮助我们诊断潜在的问题。通过监听...
名称:E10查用SQL语句集合 适用人群:ERP管理员 适用场景:E10ERP系统上线持续改善,SQL常用语句 功能描述:PO待交明细、出入库统计表、待领料清单、请购中品号无单价的品号清单、请购单中无品号采购信息的品号清单 ...
在SQL语句中,使用问号(`?`)作为参数占位符是一种常见的做法,尤其是在编程语言如Java中与数据库交互时。这种方式被称为预编译语句或参数化查询,它具有重要的安全性和性能优势。 ### SQL参数化查询的概念 参数化...
传统的数据库操作往往涉及到编写大量的SQL语句,这种方式虽然直接且高效,但对于一些初级开发者或专注于业务逻辑的开发者来说,可能会觉得繁琐。本主题将探讨如何在C#中进行不写SQL语句的数据库操作,实现对数据的增...
SQLTracker是一款专为数据库操作监控设计的工具,它在IT领域中主要用于跟踪和记录SQL语句的执行情况。SQL(Structured Query Language)是用于管理关系数据库的编程语言,包括查询、更新、插入和删除数据等操作。SQL...
在OA系统中,SQL语句是核心的数据操作工具,特别是在SQL Server数据库环境下。下面,我们将详细讨论OA系统中常见的SQL语句及其应用。 1. **人事管控**:在OA系统中,人事数据的管理和更新至关重要。例如,"01人事...
SQL语句在审计中的应用 SQL语句是数据库管理系统中使用最频繁的语言,SELECT语句是SQL语言中使用频率最高的语句。SELECT语句的作用是让数据库服务器根据用户的要求搜索出所需要的信息资料,并按规定的格式进行整理...
### ArcGIS中的SQL语句详解 #### 一、SQL在ArcGIS中的角色与应用 SQL,全称为Structured Query Language,即结构化查询语言,是专为数据库设计的一种标准语言,用于管理和操作数据库中的数据。在ArcGIS环境中,SQL...