有几个SQL语句求大神指点

作者&投稿:叶使 (若有异议请与网页底部的电邮联系)
第四大题,四个SQL语句,求大神指点~

第一题:select count(id)as '数量',id as '重复的id' from tb

第二题:update B set B.value= (select A.value from A where A.key = B.key) where exists (select B.key from B where B.key = A.key)

第三题:select AVG(e.emp_wage) as '平均工资',d.depart_name from department d ,employee e where d.dept_id = e.dept_id

第四题:select d.depart_name,e.emp_id,e.emp_wage from department d ,employee e where d.dept_id = e.dept_id and e.emp_wage>5000

思路:不知道你的BeginStationID、EndStationID这两个字段的数据类型,因为是ID我就当他们是int类型了,这样就要先把字段类型改为字符型,分别修改起点和终点。
--把字段类型先改为字符型 alter table 线路表 alter column BeginStationID varchar(20) alter table 线路表 alter column EndStationID varchar(20)--分别修改起始站和到达站 update set BeginStationID=StationName from 站点表 ,线路表 where BeginStationID=StationID update set EndStationID=StationName from 站点表 ,线路表 where EndStationID=StationID

1、insert into B(a) select a from A where a= '1'
2、create view v_create_v select * from a
   create procedure p_ctrate_table
   as 
   begin 
      select * from A
   end
3、(1)select count(*) from 职员表 group by 性别
   (2)select case  分数 when  >90 then '优' when >80 then '良' else '其他' end from  职员表
(3) select * from  职员表 having count(distinct 职员姓名) >=2
(4) select 职员性别,
sum(case when 职员性别 = '0' then 1 else 0 end) '男',
sum(case when 职员性别 = '1' then 1 else 0 end) '女' from 职员表 group by  职员性别 having count(职员性别) >=10
4、create trigger t_insert
after insert on o
for each row 
begin
update A set b=b-3 where a=1;
end



求教个SQL语句写法,关于去top10的选择
select * from table where A in (select top 10 A from table order by A desc )将所有A列数值等于取出最大十个数值的数据全部查找出来 select top 10 A from (select distinct A from table )T order by A desc 将A列数值去除重复值,然后从大到小排序,取出不重复的前十行数据 select ...

怎样用SQL语句查询一个数据库中的所有表
查询数据库里所有表名和字段名的语句 SQL 查询所有表名:SELECT NAME FROM SYSOBJECTS WHERE TYPE='U'SELECT * FROM INFORMATION_SCHEMA.TABLES 结构化查询语言(Structured Query Language)简称SQL,结构化查询语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;sql 语句...

用一条sql语句查询一个表两字段值的大小
select 字段1,字段2 from table 上面是比较简单的查法,下面的要复杂一点。不过还好拉。declare @one int;select @one=upid from users where id=10;declare @two int;select @two=urid from users where id=10 if ( @one>@two )begin print '字段一比字段二大'end else begin print '...

ORACLE SQL 查询 如何查询 某字段的 一个值 最大的前几个
附注: 1. sysplay的回答和我这个的区别是,如果 ('你',34) 这个值插入三次,那么他的语句出来的结果会出来三条,而我的结果仍然只有两条,如上图所示。 他的结果则变成如下图所示:2.两个语句应用在不同场合,他的是用来做排名的,我的仅用来排序的。不存在谁对谁错的问题,请根据实际情况...

求几条简单的SQL语句,很快的(在线等)
having count(表2.ISBN)=2 3.select t.单位,count(*),(select count(*) from test t1 where t1.性别='男' and t1.单位=t.单位) 男,(select count(*) from test t1 where t1.性别='女' and t1.单位=t.单位) 女 from test t group by t.单位 以上答案在pl\/sql中测试通过 ...

求个sql语句,两张表同一字段数值相加
-- SQLServer:update A表 a set a.A2 = a.A2 + b.A2 from B表 b where a.A1 = b.A1 -- Oracle\\MySQL:UPDATE A表 a, B表 b SET a.A2 = a.A2 + b.A2 WHERE a.A1 = b.A1

两个sql 查询语句问题,请大牛帮解,非常感谢!
第一题:select first_name,lastname from players where player_id in(select player_id from player_season_totals group by player_id having count(distinct team_id)>9 );第二题:select first_name,lastname from players where player_id in(select distinct(player_id) from player_season...

SQL语句求表中按姓名分类的最大日期值,而且“操作者=罗一”
select name, max(日期)from 表 group by name where operat='罗一'

sql查询语句大全
10、说明:几个简单的基本的sql语句 选择:select * from table1 where 范围 插入:insert into table1(field1,field2) values(value1,value2) 删除:delete from table1 where 范围 更新:update table1 set field1=value1 where 范围 查找:select * from table1 where field1 like ’%value1%’ (所有包含‘...

用oracle 写一个 sql语句 查询上一个月的最大日期,
首先获取本月第一点trunc(sysdate,'mm');这个是获取本月第一天的时间,然后-1就是上个月最后一天,然后输出日期to_char(date,'DD');最后SQL select to_char(trunc(sysdate,'mm')-1,'DD') from dual;

围场满族蒙古族自治县13380698514: 有几个SQL语句求大神指点 -
那儿小儿: 1、insert into B(a) select a from A where a= '1'2、create view v_create_v select * from a create procedure p_ctrate_table asbeginselect * from A end3、(1)select count(*) from 职员表 group by 性别 (2)select case 分数 when >90 then '优' when ...

围场满族蒙古族自治县13380698514: 求几个sql语句 -
那儿小儿: 1. select sno, grade from GRADE g where g.score >= 80 and g.score<=90; 2. select avg(g.score) from GRADE g where g.cno='002'; 3. select count(sno) from GRADE g (select sno from GRADE g group by g.cno ) as a where g.cno = a.cno; 4. select sno,sname from GRADE g where g.sname like '张%';如果表名或者列名不对应,参考GRADE改动

围场满族蒙古族自治县13380698514: sql server数据库操作有哪些? 语句有那些,语法又有哪些?忘高人指点...
那儿小儿: 操作数据库时,无非就是添加、删除、修改,常用的SQL语句: (1) 数据记录筛选: select * from 数据表 where 字段名=字段值 order by 字段名 [desc] select * from 数据表 where 字段名 like %字段值% order by 字段名 [desc] select top 10 * from ...

围场满族蒙古族自治县13380698514: SQL 查询语句,求大神支教 -
那儿小儿: 1、显示订单表中所有的信息.select * from 表名;2、列出所有中止供应的产品.select * from 产品表 where 终止供应=1;3、列出所有总订购量为0的产品.select * from 产品表 where 总订购量=0;4、列出客户表中所有客户的联系人姓名和所在公...

围场满族蒙古族自治县13380698514: 求助几个简单的sql的命令语句 -
那儿小儿: 奇怪,第一种可以,执行第二种方法提示无效:select * from card.log消息 208,级别 16,状态 1,第 1 行对象名 'card.log' 无效.调试了一下,原来还需要加多一个点,就正常了.注:列增加后将不能删除.DB2中列加上后数据类型也不能改变...

围场满族蒙古族自治县13380698514: 求SQL的语句集
那儿小儿: SQL语句之前有整理过一次,比较常用的语法吧(但不是很全),看看吧: --创建数据库 --精简型 CREATE DATABASE database_name [DATABASEPASSWORD 'database_password' [ENCRYPTION {ON|OFF}]][COLLATE collation_name ...

围场满族蒙古族自治县13380698514: SQL语句求大神指导 -
那儿小儿: 可以进行连接查询,没卖票=车票表.id is null 就可以了 select * from 车次表 left join 车票表 on 车票表.id=车次表.id where 车票表.id is null

围场满族蒙古族自治县13380698514: 求高手指点SQL查询语句 -
那儿小儿: 先生成序号字段(根据时间字段的顺序),然后计算相临的差值select DateDiff(hh,t.时间字段,t1.时间字段) from (select rank() over (order by 时间字段) as 序号,时间字段 from table1) t,(s...

围场满族蒙古族自治县13380698514: SQL语句,求大神,速度.
那儿小儿: select 员工名字,工资 from 表名 where 职务= clerk select 员工名字,工资,职务 from 表名 where 工资>3000

围场满族蒙古族自治县13380698514: SQL语句,求高手指点 -
那儿小儿: select * from (select a.*,row_number() over(partition by course order by score desc) rn from A ) where rn = 2;

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网