diff --git "a/15\351\231\210\347\253\213\346\231\272/9.26\350\247\206\345\233\276/.keep" "b/15\351\231\210\347\253\213\346\231\272/9.26\350\247\206\345\233\276/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/15\351\231\210\347\253\213\346\231\272/9.26\350\247\206\345\233\276/1\350\247\206\345\233\276.md" "b/15\351\231\210\347\253\213\346\231\272/9.26\350\247\206\345\233\276/1\350\247\206\345\233\276.md" new file mode 100644 index 0000000000000000000000000000000000000000..1fc6c62ac3342dfe4c1c8e882a2ec9c83fc2bd89 --- /dev/null +++ "b/15\351\231\210\347\253\213\346\231\272/9.26\350\247\206\345\233\276/1\350\247\206\345\233\276.md" @@ -0,0 +1,12 @@ +.视图 +1.1视图的概述 +试图(view)是数据库中的一个对象,它是数据库管理系统提供给用户的以多种角度观察数据库中数据的一种重要机制。它对应三种模式中的外模式。 +在SQL中,试图是基于SQL语句的结果集的可视化的表。 +视图包含行和列,就像一个真实的表。视图中的字段就是来自一个或多个数据库中的真实的表中的字段。但视图与基本表不同,试图是一个虚表。数据库中只存储视图的定义,而不存储视图所包含的数据,这些数据仍存放在原来的基本表中。这种模式有两个好处: +视图数据始终与基本表数据保持一致,当基本表发生变化时,从视图中查询出的数据也会随之变化。 节省存储空间。当数据量非常大时,重复存储数据非常耗费空间。 视图可以从一个基本表中提取数据,也可以从多个基本表中提取数据,甚至还可以从其他视图中提取数据,合理利用可以带来很多好处: +简化数据查询。 使用户能够从多角度看待同一数据。 提高数据的安全性。 提供了一定程度的逻辑独立性。 +CREATE VIEW <视图名> [(列名 [, ...n])] +AS + SELECT语句 +SELECT语句中通常不包含ORDER BY 和DISTINCT子句 +在定义视图时要么制定视图的全部列名,要么全部省略不写,不能只写视图的部分列名。 \ No newline at end of file diff --git "a/15\351\231\210\347\253\213\346\231\272/9.26\350\247\206\345\233\276/SQLQuery1.sql" "b/15\351\231\210\347\253\213\346\231\272/9.26\350\247\206\345\233\276/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..2299e81915c8513d4d628c6b0e2ad780c07b6ffb --- /dev/null +++ "b/15\351\231\210\347\253\213\346\231\272/9.26\350\247\206\345\233\276/SQLQuery1.sql" @@ -0,0 +1,31 @@ +--1дͼʵֲѯп˻Ϣʾţ֤ +go +create view V_newab(,֤,,) +as +select BankCard.CardNo,AccountInfo.AccountCode,AccountInfo.RealName,BankCard.CardMoney from BankCard left join AccountInfo on BankCard.AccountId=AccountInfo.AccountId +go +--2תг: group by + sum(case when) /+count(case when) ݷ+ over (paritition by, order by) +create table record( + id int primary key identity(1,1), + year1 int not null , + month1 int not null, + amount float not null +) +insert into record values +(1991,1,1.1), +(1991,2,1.2), +(1991,3,1.3), +(1991,4,1.4), +(1992,1,2.1), +(1992,2,2.2), +(1992,3,2.3), +(1992,4,2.4) +select * from record +go +select year1, +sum(case when month1=1 then amount end) m1, +sum(case when month1=2 then amount end) m2, +sum(case when month1=3 then amount end) m3, +sum(case when month1=4 then amount end) m4 +from record +group by year1 \ No newline at end of file