1、
創(chuàng)新互聯(lián)是一家專(zhuān)注于成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),騰沖網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專(zhuān)注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計(jì)領(lǐng)域的專(zhuān)業(yè)建站公司;建站業(yè)務(wù)涵蓋:騰沖等地區(qū)。騰沖做網(wǎng)站價(jià)格咨詢(xún):18982081108
CREATE FUNCTION return_num
(@Class_Num varchar(20) )
RETURNS int
AS
BEGIN
RETURN ( select cout(*) from classmates where classnum=@Class_Num )
END
3、
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database 數(shù)據(jù)庫(kù)名字' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database 數(shù)據(jù)庫(kù)名字'
IF (@@ERROR 0 OR @ReturnCode 0) GOTO QuitWithRollback
END
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'備份數(shù)據(jù)庫(kù)名字',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'每天上午數(shù)據(jù)庫(kù)備份',
@category_name=N'Database 數(shù)據(jù)庫(kù)名字',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR 0 OR @ReturnCode 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Daily Backup',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'declare @strDate nvarchar(max);
set @strDate = N''D:\DataBaseAutoBackup\數(shù)據(jù)庫(kù)名字_'' + Convert(nvarchar(8),getdate(),112) + N''.bak''
BACKUP DATABASE [數(shù)據(jù)庫(kù)名字] TO DISK = @strDate WITH NOFORMAT, NOINIT, NAME = N''數(shù)據(jù)庫(kù)名字_Dev-完整 數(shù)據(jù)庫(kù) 備份'', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO',
@database_name=N'master',
@flags=0
IF (@@ERROR 0 OR @ReturnCode 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR 0 OR @ReturnCode 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Daily Backup',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=1,
@freq_subday_interval=0,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20120510,
@active_end_date=99991231,
@active_start_time=50000,
@active_end_time=235959,
@schedule_uid=N'f90cfdc3-cb5d-4e19-9e93-99b8921d36c0'
IF (@@ERROR 0 OR @ReturnCode 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR 0 OR @ReturnCode 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT 0) ROLLBACK TRANSACTION
EndSave:
GO
1、select * from (select *,row_number() over (partition by c# order by score desc) as r from sc) where r in (1,2)
2、select c#,count(*) from sc group by c# order by count(*)
3、select sc.s#,st.sname from sc where c#=01 and score 80 left join st on sc.s#=st.s#
4、select st.*,sc.c#,sc.score from sc left join sc on st.s#=sc.s#(具體課程教師再用left join連接)
5、select * from 題目4 where sname like "%風(fēng)%"
1、忍不住想說(shuō)一句,因?yàn)榈谝活}中的字段類(lèi)型是
【日期型】,而各種數(shù)據(jù)庫(kù)操作日期型數(shù)據(jù)有不同的方法,沒(méi)有一種共通的方法,所以脫離了數(shù)據(jù)庫(kù)而言沒(méi)有一種共通的sql。
2、select
ID,NAME,ADDRESS,PHONE,LOGDATE
from
T
where
ID
in(
select
ID
from
T
group
by
NAME
having
count(*)1)
order
by
NAME;
3、delete
from
T
where
ID
not
in
(select
min(id)
from
T
group
by
name);
4、update
T
set
T.ADDRESS=(select
E.ADDRESS
from
E
where
E.NAME=T.NAME),
T.PHONE=(select
E.PHONE
from
E
where
E.NAME=T.NAME);
5、這個(gè)不同的數(shù)據(jù)庫(kù)也有不同的處理方法,不能脫離數(shù)據(jù)庫(kù)談了。
如:SqlServer或者access可以使用
top
oracle可以使用
rownum
等
---
以上,希望對(duì)你有所幫助。
1. select 學(xué)生.學(xué)號(hào) as 至少選修2門(mén)課程學(xué)生學(xué)號(hào) from 學(xué)生 group by 學(xué)生.學(xué)號(hào) where 學(xué)生.學(xué)號(hào)=(select 學(xué)號(hào) form 成績(jī) where 學(xué)生.學(xué)號(hào)=成績(jī).學(xué)號(hào))
2.select 課程.課程號(hào) as 王文芳同學(xué)不學(xué)的課程的課程號(hào) from 課程 where 課程.課程號(hào) not in
(
select 成績(jī).課程號(hào) from 成績(jī)
where 成績(jī).學(xué)號(hào) in(select 學(xué)生.學(xué)號(hào) from 學(xué)生 where 姓名='王文芳')
)
3、查詢(xún)出課程號(hào)為‘002’,分?jǐn)?shù)最高的學(xué)生學(xué)號(hào)
三、查詢(xún)?cè)O(shè)計(jì)
1、SELECT?學(xué)號(hào),姓名?FROM?學(xué)生
WHERE?班級(jí)?=?'軟件041'
2、SELECT?*?FROM?課程
WHERE?課程名稱(chēng)?LIKE?'%語(yǔ)言%'
3、SELECT?D.學(xué)號(hào),D.姓名,D.班級(jí)
FROM?(
SELECT?TOP?5?學(xué)號(hào)?
FROM?選課?A
LEFT?JOIN?課程?B
ON?A.課程號(hào)?=?B.課程號(hào)
WHERE?B.課程名稱(chēng)?=?'C語(yǔ)言'
ORDER?BY?A.成績(jī)?DESC
)?C
LEFT?JOIN?學(xué)生?D
ON?C.學(xué)號(hào)?=?D.學(xué)號(hào)
4、SELECT?班級(jí),COUNT(班級(jí))
FROM?學(xué)生
GROUP?BY?班級(jí)
5、DECLARE?@zhangsanchengji?FLOAT
SELECT?@zhangsanchengji?=?A.成績(jī)
FROM?選課?A
LEFT?JOIN?課程?B
ON?A.課程號(hào)?=?B.課程號(hào)
LEFT?JOIN?學(xué)生?C
ON??A.學(xué)號(hào)?=?C.學(xué)號(hào)
WHERE?B.課程名稱(chēng)?=?'計(jì)算機(jī)應(yīng)用基礎(chǔ)'
AND?A.姓名?=?'張三'
SELECT?D.學(xué)號(hào),D.姓名
FROM?(
SELECT?A.學(xué)號(hào),A.成績(jī)
FROM?選課?A
LEFT?JOIN?課程?B
ON?A.課程號(hào)?=?B.課程號(hào)
WHERE?B.課程名稱(chēng)?=?'計(jì)算機(jī)應(yīng)用基礎(chǔ)'
)?C
LEFT?JOIN?學(xué)生?D
ON?C.學(xué)號(hào)?=?D.學(xué)號(hào)
WHERE?成績(jī)??@zhangsanchengji
五、操作題,這里自己查相關(guān)的操作吧,不好描述,sqlserver軟件操作起來(lái)還是挺方便的。
3、A
break:是跳出本次循環(huán),也就是當(dāng)@n = 1,循環(huán)終止并跳出begin-end執(zhí)行外部的代碼,此時(shí)@n = 1。
continue:重新開(kāi)始循環(huán),但是continue后的代碼不執(zhí)行的,這里直到@n = 0時(shí)。
return:過(guò)程中無(wú)條件退出,后續(xù)的所有代碼都不執(zhí)行,所以不會(huì)有輸出。