From 27545baf41890fe77aab1b1bd267f13c3c360fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E7=8E=AE=E5=96=86?= Date: Tue, 27 Sep 2022 22:44:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=83=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3\346\254\241\344\275\234\344\270\232.txt" | 30 +++++++++++++++++++ .../2022.09.26-\350\247\206\345\233\276.md" | 27 +++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 "04\351\203\221\347\216\256\345\226\206/\344\275\234\344\270\232/2022.09.26-\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.txt" create mode 100644 "04\351\203\221\347\216\256\345\226\206/\347\254\224\350\256\260/2022.09.26-\350\247\206\345\233\276.md" diff --git "a/04\351\203\221\347\216\256\345\226\206/\344\275\234\344\270\232/2022.09.26-\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.txt" "b/04\351\203\221\347\216\256\345\226\206/\344\275\234\344\270\232/2022.09.26-\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.txt" new file mode 100644 index 0000000..b1a33d4 --- /dev/null +++ "b/04\351\203\221\347\216\256\345\226\206/\344\275\234\344\270\232/2022.09.26-\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.txt" @@ -0,0 +1,30 @@ +--编写视图实现查询出所有银行卡账户信息,显示卡号,身份证,姓名,余额。 +create view v_information +as +select AccountCode,CardNo,RealName,CardMoney from AccountInfo inner join BankCard on BankCard.AccountId=AccountInfo.AccountId +go +select * from v_information +drop view v_information + + + +--行转列 +create table huatai( + year int, + month int, + amount float +) + +insert into huatai(year,month,amount) values (1991,1,1.1) +insert into huatai(year,month,amount) values (1991,2,1.2) +insert into huatai(year,month,amount) values (1991,3,1.3) +insert into huatai(year,month,amount) values (1991,4,1.4) + +insert into huatai(year,month,amount) values (1992,1,2.1) +insert into huatai(year,month,amount) values (1992,2,2.2) +insert into huatai(year,month,amount) values (1992,3,2.3) +insert into huatai(year,month,amount) values (1992,4,2.4) + +select * from huatai + +select * from huatai pivot(max(amount) for month in ([1],[2],[3],[4])) a \ No newline at end of file diff --git "a/04\351\203\221\347\216\256\345\226\206/\347\254\224\350\256\260/2022.09.26-\350\247\206\345\233\276.md" "b/04\351\203\221\347\216\256\345\226\206/\347\254\224\350\256\260/2022.09.26-\350\247\206\345\233\276.md" new file mode 100644 index 0000000..e53d2df --- /dev/null +++ "b/04\351\203\221\347\216\256\345\226\206/\347\254\224\350\256\260/2022.09.26-\350\247\206\345\233\276.md" @@ -0,0 +1,27 @@ +7、视图 + +创建视图 + + create view V_name as select row_name from table_name + +删除视图 + + drop view V_name + +###  union + + SELECT _column_name(s)_ FROM _table1_ + UNION + SELECT _column_name(s)_ FROM _table2_ + +### union all + + SELECT _column_name(s)_ FROM _table1_ + UNION ALL + SELECT _column_name(s)_ FROM _table2_ + +### unpivot + +select from Sales + + unpivot (Amount for people in (A1,A2,A3,A4) as a \ No newline at end of file -- Gitee