1. 关于数据库的语句该怎样写·
create table student( sno char(5) primary key, sname varchar(20), ssex bit, sage numeric(2,0), sdept varchar(20)); create table course( cno char(3) primary key, cname varchar(16), cpno char(23), ccredit numeric(1,0)); create table sc( sno char(5), cno char(3), grade numeric(5,1), primary key (sno,cno), foreign key(sno) references student(sno), foreign key(cno) references course(cno));1.统计每个学生的选课数量 (结果显示学号和选课数量,按选课数量升序排列) select sno, count(*) as number from sc group by sno order by number2.统计信息系每个学生的选课数量 (结果显示学号、姓名和选课数量,按选课数量升序排列) select sc.sno, stu.sname, a.number from sc,student as stu,(select sno,count(*) as number from sc,student where sc.sno in (select sno from student where sdept = "信息系") group by sno) as a order by number3.统计至少选了4门课的每个学生的选课数量(结果显示学号、姓名和选课数量,按选课数量升序排列) select sc.sno,stu.sname, a.number from sc,student as stu,(select sno,count(*) as number from sc group by sno) as a where a.number >=44.统计每个课程的最高分 (结果显示课程编号和最高分,按分数降序排列) select sc.cno,MAX(grade) from sc group by cno order by grade DESC5.统计学分大于等于3分的每个课程的最高分(结果显示课程编号、课程名和最高分,按分数降序排列) select sc.cno,MAX(grade) from sc where sc.cno in(select course.cno,course.cname,course.ccredit from course where ccredit >= 3) group by sc.cno order by grade DESC。
2. 在数据库里面插入数据的语句怎么写
用insert语句: INSERT INTO table1(id, name, address) VALUES(1, ygl, 'beijing'),该语句主要适用于sql和PL/SQL。
拓展资料
数据库(Database)是按照数据结构来组织、存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和市场的发展而发展。目前,数据库有很多种类型,从最简单的存储有各种数据的表格到能够进行海量数据存储的大型数据库系统都在各个方面得到了广泛的应用。
结构化查询语言(Structured Query Language)简称SQL(发音:/ˈes kjuː ˈel/ "S-Q-L"),是一种特殊目的的编程语言,是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;同时也是数据库脚本文件的扩展名。
3. 关于数据库的语句该怎样写·
create table student(
sno char(5) primary key,
sname varchar(20),
ssex bit,
sage numeric(2,0),
sdept varchar(20)
);
create table course(
cno char(3) primary key,
cname varchar(16),
cpno char(23),
ccredit numeric(1,0)
);
create table sc(
sno char(5),
cno char(3),
grade numeric(5,1),
primary key (sno,cno),
foreign key(sno) references student(sno),
foreign key(cno) references course(cno)
);
1.统计每个学生的选课数量 (结果显示学号和选课数量,按选课数量升序排列)
select sno, count(*) as number from sc group by sno order by number
2.统计信息系每个学生的选课数量 (结果显示学号、姓名和选课数量,按选课数量升序排列)
select sc.sno, stu.sname, a.number from sc,student as stu,(select sno,count(*) as number from sc,student where sc.sno in (select sno from student where sdept = "信息系") group by sno) as a order by number
3.统计至少选了4门课的每个学生的选课数量(结果显示学号、姓名和选课数量,按选课数量升序排列)
select sc.sno,stu.sname, a.number from sc,student as stu,(select sno,count(*) as number from sc group by sno) as a where a.number >=4
4.统计每个课程的最高分 (结果显示课程编号和最高分,按分数降序排列)
select sc.cno,MAX(grade) from sc group by cno order by grade DESC
5.统计学分大于等于3分的每个课程的最高分(结果显示课程编号、课程名和最高分,按分数降序排列)
select sc.cno,MAX(grade) from sc where sc.cno in(select course.cno,course.cname,course.ccredit from course where ccredit >= 3) group by sc.cno order by grade DESC
4. sql常用语句写法
1、说明:创建数据库CREATE DATABASE database-name 2、说明:删除数据库drop database dbname 3、说明:备份sql server --- 创建 备份数据的 deviceUSE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:mssql7backupMyNwind_1.dat' --- 开始 备份BACKUP DATABASE pubs TO testBack 4、说明:创建新表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..) 根据已有的表创建新表: A:create table tab_new like tab_old (使用旧表创建新表)
B:create table tab_new as select col1,col2… from tab_old definition only 5、说明: 删除新表:drop table tabname 6、说明: 增加一个列:Alter table tabname add column col type 注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。 7、说明: 添加主键:Alter table tabname add primary key(col) 说明: 删除主键:Alter table tabname drop primary key(col) 8、说明: 创建索引:create [unique] index idxname on tabname(col….) 删除索引:drop index idxname 注:索引是不可更改的,想更改必须删除重新建。 9、说明: 创建视图:create view viewname as select statement 删除视图:drop view viewname 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%' ---like的语法很精妙,查资料! 排序:select * from table1 order by field1,field2 [desc] 总数:select count * as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:select min(field1) as minvalue from table1
5. 求问SQL数据库中匹配语句怎么写
ms sql 的replace语句不支持通配符,只能通过substring来操作。由于可能有多个<?>;需要替换,因此可以写一个函数,循环替换。
CREATE FUNCTION [myReplace]
(@str varchar(2000))
RETURNS varchar(2000)
WITH EXECUTE AS CALLER
AS
BEGIN
declare @tmp varchar(2000)
set @tmp=@str;
declare @succ int
set @succ=0;
declare @i int
declare @j int
while (@succ=0)
begin
set @i=charindex('<',@tmp);
set @j=charindex('>',@tmp);
if (@i>0 and @j>0) --如果有<;和>
begin
set @tmp=replace(@tmp,substring(@tmp,@i,@j-@i+1),'')
end
else--否则已处理完,结束循环
begin
set @succ=1;
end
end
return @tmp
接下来,update语句这样写就行了:
update infos_content set content = dbo.myReplace(content)
6. SQL语句怎么写
select * from b where b.id not in (select id from a);
select b.* from a,b
minus
select a.t_id from a,b
where a.t_id = b.t_id;
select * from b where not exists (select 1 from a where a.t_id = b.t_id);
以上三种都可以的
7. SQL语句要怎么写
首先,要得到,一个月的倒数第二天啊
select last_day(sysdate)-1 from dual
用last_day 函数,得到最后一天,然后,再 减去1 就得到 一个月的倒数第二天。
第二个问题,是,要对表中出现的月 都 要 进行 倒数第二天的计算
select distinct( last_day(到职日期)-1) from 员工信息
这个检索的语句,就是,得到 表中,各个月的倒数第二天。
最后的SQL就是
select * from 员工信息
where 到职日期 in (
select distinct( last_day(到职日期)-1) from 员工信息
)
哈哈,不知我说的清楚没有
我用的是ORACEL 数据库
8. 在数据库中添加一行的SQL语句怎么写啊
选择:select * from 表名 where 条件
插入:insert into 表名(字段名1,字段名2) values(值1,值2)
删除:delete from 表名 where 条件
更新:update 表名 set 要更新的字段名=值 where 条件
查找:select * from 表名 where 字段名 like '%值% '----------模糊查询,如查苏州,他会查出美苏州,苏州好等类似字段 /////////////////////////////////////这些是基本的增,删,查,改的SQL语句,希望对你有帮助
9. 请教个SQL语句怎么写.
下面的几条语句完成向A表插入10000条C=1,D=2,E=3的记录:
DECLARE @C INT,@D INT,@E INT,@COUNT INT
SELECT @C=1,@D=2,@E=3,@COUNT=10000
WHILE @COUNT>0
BEGIN
insert into A表(C,D,E) VALUES(@C,@D,@E)
SET @COUNT=@COUNT-1
END