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