diff --git "a/47\346\233\276\345\276\267\346\243\256/2022-9-26-\350\247\206\345\233\276\347\273\203\344\271\240/.keep" "b/47\346\233\276\345\276\267\346\243\256/2022-9-26-\350\247\206\345\233\276\347\273\203\344\271\240/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/47\346\233\276\345\276\267\346\243\256/2022-9-26-\350\247\206\345\233\276\347\273\203\344\271\240/\346\233\276\345\276\267\346\243\256/\344\275\234\344\270\232/\350\247\206\345\233\276\347\254\224\350\256\260.md" "b/47\346\233\276\345\276\267\346\243\256/2022-9-26-\350\247\206\345\233\276\347\273\203\344\271\240/\346\233\276\345\276\267\346\243\256/\344\275\234\344\270\232/\350\247\206\345\233\276\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..5564dfe59dd9acd262838eb753bfbf22ebf5d39c --- /dev/null +++ "b/47\346\233\276\345\276\267\346\243\256/2022-9-26-\350\247\206\345\233\276\347\273\203\344\271\240/\346\233\276\345\276\267\346\243\256/\344\275\234\344\270\232/\350\247\206\345\233\276\347\254\224\350\256\260.md" @@ -0,0 +1,60 @@ +--视图: +--数据表:1.基表 2.临时表(select,) 3.视图(虚拟表) + + +--创建 view:视图 index:索引 proc:存储过程 + + + +--查询学生信息:学号,姓名,学院 +select stu_num, name, school from tb_student + +go +create view V_GetInfo +as +select stu_num, name, school from tb_student +go +--使用 +--视图是一张虚拟表 +select * from V_GetInfo --》视图转化: select stu_num, name, school from tb_student + +--删除 +--drop view V_GetInfo + + +--统计各个生源地的荣誉总数 +select * from tb_inf_student + +select ori_loca , sum(prize) 荣誉总数 from tb_inf_student group by ori_loca + + +create view V_GetTotalPrize(生源地,荣誉总数) +as +select ori_loca , sum(prize) from tb_inf_student group by ori_loca + +select * from V_GetTotalPrize + +drop view V_GetTotalPrize + + +--建立信息学院学生的视图 +create view V_Info +as +select * from tb_student where school='信息学院' +with check option --涉及的增删只能对信息学院的学生进行操作 + +--drop view V_Info + +select * from V_Info + +update V_Info set gender=1 where name = '博文' + +insert into V_info values('10114','蜗牛',1,getdate(),'理学院','计科') + + +--定义一个反映学生年龄的视图 +create view V_GetAgeByBirth(学号,姓名,年龄) +as +select stu_num,name, (year(getdate()) - year(birth)) from tb_student + +select * from V_GetAgeByBirth \ No newline at end of file diff --git "a/47\346\233\276\345\276\267\346\243\256/2022-9-26-\350\247\206\345\233\276\347\273\203\344\271\240/\346\233\276\345\276\267\346\243\256/\347\254\224\350\256\260/SQLQuery2.sql" "b/47\346\233\276\345\276\267\346\243\256/2022-9-26-\350\247\206\345\233\276\347\273\203\344\271\240/\346\233\276\345\276\267\346\243\256/\347\254\224\350\256\260/SQLQuery2.sql" new file mode 100644 index 0000000000000000000000000000000000000000..69a665fd7a9fe7f0bc704ddbce74283adc4ca418 --- /dev/null +++ "b/47\346\233\276\345\276\267\346\243\256/2022-9-26-\350\247\206\345\233\276\347\273\203\344\271\240/\346\233\276\345\276\267\346\243\256/\347\254\224\350\256\260/SQLQuery2.sql" @@ -0,0 +1,19 @@ +--1.дͼʵֲѯп˻Ϣʾţ֤ +create view View_Account_Card +as +select CardNo ,AccountCode ֤,RealName ,CardMoney from AccountInfo +inner join BankCard on AccountInfo.AccountId = BankCard.AccountId +go +; + + + +--2.תг: group by + sum(case when) /+count(case when) ݷ+ over (paritition by, order by) +select year, +max(case month when 1 then amount else 0 end) m1, +max(case month when 2 then amount else 0 end) m2, +max(case month when 3 then amount else 0 end) m3, +max(case month when 4 then amount else 0 end) m4 +from securities +group by year +; \ No newline at end of file