❶ 怎麼創建一個存儲過程批量處理所有學生平均成績,並顯示平均成績前五名的同學
----假設涉及學生表和分數表,課程表
create procere GetTop5
as
begin
select top 5 StudentName
(
select avg(sc.score) as '平均分數' ,s.StudentCode,s.StudentName
from Score sc
inner join Student s on sc.studentCode = s.studentCode
inner join Subject c on sc.SubjectCode = c.SubjectCode
group by s.StudentCode,s.StudentName
)t
order by 平均分數 desc
end
go
❷ 存儲過程查詢一個表的數據有很多條數據,在java調用這個存儲過程怎樣讓數據根據他的時間只顯示前三條
這個根據你的問題.最簡易的解決辦法就是設置一個大小為3的數組,專門保存前面3個數據
就在你的那個rs.next 那個遍歷裡面做..遍歷到每條數據 就和數組裡面的數據進行比較..最終遍歷結束 存的三個就是最終的結果了
❸ mysql存儲過程中處理多條數據
插入進另一個表裡, SQL語句不是僅僅運用在本表內的,可以多表嵌套 這個不要忽略
❹ Oracle存儲過程統計信息
不需要execute,直接寫dbms_stats.gather_table_stats(就可以,而且專門寫個存儲過程沒意義。
❺ sql 查詢每個班前十名
表建的很不合理啊
首先,班級要一張表
學生信息要一張表
成績一張表
建資料庫要有遵守三條原則啊,不然也很不方便查詢
你這題,用分組也沒辦查. 樓上兩位完全就是騙分的...沒一個正確的
就說一樓的這句SELECT TOP 10 * FROM 表名 WHERE 條件 ORDER BY 成績 DESC ...請問條件是什麼?
再說二樓的selet top 10 * from 學生表 order by 成績 desc
你這查出來的只是所有班所有前十名的成績.而不是每個班的前十名
如果表只有一張,只能分班查...比如班級列叫calss,其中有一個班級Classone
select top 10 * from 表名 where class='Classone' order by 成績
❻ 一個存儲過程的統計代碼怎麼寫
select distinct count(*)from 表名
distinct 去除重復值;
count(*) 統計記錄數
❼ 編寫顯示部門信息的存儲過程,統計各部門人數,oracle
create or replace package pkg_types
is
type my_cursor is ref cursor ;
end ;
create or replace procere p_sum_dept( ocur out pkg_types.my_cursor)
is
begin
open ocur for
select deptno
count(empno)
from employee
group by deptno;
end ;
/
❽ sql server2000存儲過程中如何使用函數或者什麼,截取欄位前幾位的內容,例如asp中的mid()函數功能
SUBSTRING
返回字元、binary、text 或 image 表達式的一部分。有關可與該函數一起使用的有效 Microsoft® SQL Server™ 數據類型的更多信息,請參見數據類型。
語法
SUBSTRING ( expression , start , length )
參數
expression
是字元串、二進制字元串、text、image、列或包含列的表達式。不要使用包含聚合函數的表達式。
start
是一個整數,指定子串的開始位置。
length
是一個整數,指定子串的長度(要返回的字元數或位元組數)。
說明 由於在 text 數據上使用 SUBSTRING 時 start 和 length 指定位元組數,因此 DBCS 數據(如日本漢字)可能導致在結果的開始或結束位置拆分字元。此行為與 READTEXT 處理 DBCS 的方式一致。然而,由於偶而會出現奇怪的結果,建議對 DBCS 字元使用 ntext 而非 text。
返回類型
如果 expression 是支持的字元數據類型,則返回字元數據。如果 expression 是支持的 binary 數據類型,則返回二進制數據。
返回字元串的類型與給定表達式的類型相同(表中顯示的除外)。
給定的表達式 返回類型
text varchar
image varbinary
ntext nvarchar
注釋
在字元數中必須指定使用 ntext、char 或 varchar 數據類型的偏移量(start 和 length)。在位元組數中必須指定使用 text、image、binary 或 varbinary 數據類型的偏移量。
說明 兼容級別可能影響返回值。有關兼容級別的更多信息,請參見 sp_dbcmptlevel。
示例
A. 在字元串上使用 SUBSTRING
下例顯示如何只返回字元串的一部分。該查詢在一列中返回 authors 表中的姓氏,在另一列中返回 authors 表中的名字首字母。
USE pubs
SELECT au_lname, SUBSTRING(au_fname, 1, 1)
FROM authors
ORDER BY au_lname
下面是結果集:
au_lname
---------------------------------------- -
Bennet A
Blotchet-Halls R
Carson C
DeFrance M
del Castillo I
...
Yokomoto A
(23 row(s) affected)
下例顯示如何顯示字元串常量 abcdef 中的第二個、第三個和第四個字元。
SELECT x = SUBSTRING('abcdef', 2, 3)
下面是結果集:
x
----------
bcd
(1 row(s) affected)
B. 在 text、ntext 和 image 數據上使用 SUBSTRING
下例顯示如何從 pubs 資料庫的 publishers 表內的每個 text 和 image 數據列中返回前 200 個字元。text 數據以 varchar 的形式返回,image 數據則以 varbinary 的形式返回。
USE pubs
SELECT pub_id, SUBSTRING(logo, 1, 10) AS logo,
SUBSTRING(pr_info, 1, 10) AS pr_info
FROM pub_info
WHERE pub_id = '1756'
下面是結果集:
pub_id logo pr_info
------ ---------------------- ----------
1756 0x474946383961E3002500 This is sa
(1 row(s) affected)
下例顯示 SUBSTRING 在 text 和 ntext 數據上的效果。首先,下例在 pubs 資料庫內創建一個名為 npr_info 的新表。然後,在 npr_info 表中用 pub_info.pr_info 列的前 80 個字元創建 pr_info 列,並添加ü作為首字元。最後,INNER JOIN 檢索所有出版商標識號以及 text 和 ntext 出版商信息列的 SUBSTRING。
IF EXISTS (SELECT table_name FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = 'npub_info')
DROP TABLE npub_info
GO
-- Create npub_info table in pubs database. Borrowed from instpubs.sql.
USE pubs
GO
CREATE TABLE npub_info
(
pub_id char(4) NOT NULL
REFERENCES publishers(pub_id)
CONSTRAINT UPKCL_npubinfo PRIMARY KEY CLUSTERED,
pr_info ntext NULL
)
GO
-- Fill the pr_info column in npub_info with international data.
RAISERROR('Now at the inserts to pub_info...',0,1)
GO
INSERT npub_info VALUES('0736', N'üThis is sample text data for New Moon Books, publisher 0736 in the pubs database')
INSERT npub_info values('0877', N'üThis is sample text data for Binnet & Hardley, publisher 0877 in the pubs databa')
INSERT npub_info values('1389', N'üThis is sample text data for Algodata Infosystems, publisher 1389 in the pubs da')
INSERT npub_info values('9952', N'üThis is sample text data for Scootney Books, publisher 9952 in the pubs database')
INSERT npub_info values('1622', N'üThis is sample text data for Five Lakes Publishing, publisher 1622 in the pubs d')
INSERT npub_info values('1756', N'üThis is sample text data for Ramona Publishers, publisher 1756 in the pubs datab')
INSERT npub_info values('9901', N'üThis is sample text data for GGG&G, publisher 9901 in the pubs database. GGG&G i')
INSERT npub_info values('9999', N'üThis is sample text data for Lucerne Publishing, publisher 9999 in the pubs data')
GO
-- Join between npub_info and pub_info on pub_id.
SELECT pr.pub_id, SUBSTRING(pr.pr_info, 1, 35) AS pr_info,
SUBSTRING(npr.pr_info, 1, 35) AS npr_info
FROM pub_info pr INNER JOIN npub_info npr
ON pr.pub_id = npr.pub_id
ORDER BY pr.pub_id ASC
❾ 求一條SQL語句:能一次計算出各科前10名學生的平均成績。
select '語文' as 科目, avg(語文) as 平均成績 from
(select top 10 語文 from 成績表 order by 語文 desc) as x
union all
select '數學' as 科目, avg(數學) as 平均成績 from
(select top 10 數學 from 成績表 order by 數學 desc) as y
union all
select '英語' as 科目, avg(英語) as 平均成績 from
(select top 10 英語 from 成績表 order by 英語 desc) as z
如果還有其它科目,可以用同樣的方式往後加。
❿ ·創建存儲過程統計各教師任課的學生人數;Oracle回答
創建
1
2
3
4
5
create
proc
p_sumsocre
as
select
a.學號,a.姓名,sum(b.學分)
as
總學分
from
學生表
a,課程表
b,選課表
c
where
a.學號=c.學號
and
b.課程號=c.課程號
執行
1
exec
p_sumsocre
以上為sqlserver
寫法,其他資料庫寫法不同