diff --git "a/20\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" similarity index 100% rename from "20\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" rename to "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\347\254\224\350\256\260.md" similarity index 94% rename from "20\347\216\213\344\270\226\350\264\242/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" rename to "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\347\254\224\350\256\260.md" index 1d4f017fa879ef9163b7d6049805bde06c96c12d..a4d8a8503939565a3cbfd8d142542bff510487c7 100644 --- "a/20\347\216\213\344\270\226\350\264\242/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\347\254\224\350\256\260.md" @@ -38,7 +38,7 @@ ClassID int references ClassInfo(ClassID) userName varchar(10) unique ``` -- check +- check - 如果对单个列定义 CHECK 约束,那么该列只允许特定的值。 diff --git "a/\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232.sql" "b/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" similarity index 98% rename from "\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232.sql" rename to "20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" index 1f50239075a77feeaeb348c59ea24f9d1560d163..a2e93a45441aed24f210f83c40ebecc3472a8d25 100644 --- "a/\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232.sql" +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" @@ -6,13 +6,13 @@ where PeopleAddress='武汉' --2. 查询出武汉地区所有的员工信息,要求显示部门名称,职级名称以及员工的详细资料 -select * from People +select * from People inner join Department on People.DepartmentId=Department.DepartmentId inner join Rank on People.RankId=Rank.RankId where PeopleAddress ='武汉' --3. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资。 - + select DepartmentName,COUNT(People.DepartmentId)人数,SUM(PeopleSalary)工资总和,AVG(PeopleSalary)平均工资,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People inner join Department on People.DepartmentId=Department.DepartmentId group by DepartmentName @@ -37,29 +37,29 @@ select * from People where MONTH(PeopleBirth)+CONVERT(float,DAY(PeopleBirth))/10 --7.查询所有员工信息,添加一列显示属相(鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪) -select *, case - when year(PeopleBirth)%12 =0 - then '猴' - when YEAR(PeopleBirth)%12=1 - then '鸡' - when YEAR(PeopleBirth)%12=2 - then '狗' - when YEAR(PeopleBirth)%12=3 - then '猪' - when YEAR(PeopleBirth)%12=4 - then '鼠' - when YEAR(PeopleBirth)%12=5 - then '牛' - when YEAR(PeopleBirth)%12=6 - then '虎' - when YEAR(PeopleBirth)%12=7 - then '兔' - when YEAR(PeopleBirth)%12=8 - then '龙' - when YEAR(PeopleBirth)%12=9 - then '蛇' - when YEAR(PeopleBirth)%12=10 - then '马' - when YEAR(PeopleBirth)%12=11 - then '羊' +select *, case + when year(PeopleBirth)%12 =0 + then '猴' + when YEAR(PeopleBirth)%12=1 + then '鸡' + when YEAR(PeopleBirth)%12=2 + then '狗' + when YEAR(PeopleBirth)%12=3 + then '猪' + when YEAR(PeopleBirth)%12=4 + then '鼠' + when YEAR(PeopleBirth)%12=5 + then '牛' + when YEAR(PeopleBirth)%12=6 + then '虎' + when YEAR(PeopleBirth)%12=7 + then '兔' + when YEAR(PeopleBirth)%12=8 + then '龙' + when YEAR(PeopleBirth)%12=9 + then '蛇' + when YEAR(PeopleBirth)%12=10 + then '马' + when YEAR(PeopleBirth)%12=11 + then '羊' end 生肖 from People \ No newline at end of file diff --git "a/\347\216\213\344\270\226\350\264\242/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" similarity index 97% rename from "\347\216\213\344\270\226\350\264\242/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" rename to "20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" index ffd706a81a480c72fb448728b472cc3db8cfed3e..6064e66b1bcaf6ab73bd58e676e0b14ddd2b8ac6 100644 --- "a/\347\216\213\344\270\226\350\264\242/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" @@ -6,7 +6,7 @@ select * from Department where DepartmentId like '[1-3]' // [1-3] == 1,2,3 - + select * from Department where DepartmentId like '[^1-3]' //[^1-3] == 4 diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232.sql" "b/20\347\216\213\344\270\226\350\264\242/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..6a0f745b40e995b24ce6225f5aca34bfd9372f45 --- /dev/null +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232.sql" @@ -0,0 +1,64 @@ +--1. 关羽的银行卡号为"6225547858741263",查询出余额比关羽多的银行卡信息,显示卡号,身份证,姓名,余额。---- +select t.CardNo 卡号,a.AccountCode,a.RealName,t.CardMoney from AccountInfo a +inner join +( +select * from BankCard where CardMoney > ( +select CardMoney from BankCard where CardNo = '6225547858741263') +) t +on t.AccountId = a.AccountId + + +--2. 从所有账户信息中查询出余额最高的交易明细(存钱取钱信息)。 +select top 1 *,(MoneyInBank-MoneyOutBank) 余额 from CardExchange +order by 余额 desc + +--3. 查询有取款记录的银行卡及账户信息,显示卡号,身份证,姓名,余额。 +select t1.CardNo 卡号,a.AccountCode 身份证,a.RealName 姓名, t1.余额 from AccountInfo a +inner join +( +select b.*,t.余额 from BankCard b +inner join +( +select *,(MoneyInBank-MoneyOutBank) 余额 +from CardExchange +where MoneyOutBank != 0 +) t +on b.CardNo = t.CardNo +) t1 +on t1.AccountId = a.AccountId + +--4. 查询出没有存款记录的银行卡及账户信息,显示卡号,身份证,姓名,余额。 +select * from BankCard where CardNo not in +( +select CardNo from CardExchange +) +--5. 关羽的银行卡号为"6225547858741263",查询当天是否有收到转账。 + +if exists( select * from CardTransfer where CardNoIn = '6225547858741263') +print '有收到转账' +else +print'未收到转账' +--6. 查询出交易次数(存款取款操作)最多的银行卡账户信息,显示:卡号,身份证,姓名,余额,交易次数。 + +select top 1 BankCard.CardNo 卡号,AccountCode 身份证,RealName 姓名,CardMoney 余额, +exchangeCount 交易次数 from BankCard +inner join AccountInfo on BankCard.AccountId = AccountInfo.AccountId +inner join +(select CardNo,COUNT(*) exchangeCount from CardExchange group by CardNo) CarcExchageTemp +on BankCard.CardNo = CarcExchageTemp.CardNo +order by exchangeCount desc + +--7. 查询出没有转账交易记录的银行卡账户信息,显示卡号,身份证,姓名,余额-- +select CardNo 卡号,AccountCode 身份证,RealName 姓名,CardMoney 余额 from BankCard +left join AccountInfo on BankCard.AccountId = AccountInfo.AccountId +where BankCard.CardNo not in (select CardNoIn from CardTransfer) +and BankCard.CardNo not in (select CardNoOut from CardTransfer) + + + + + + + + + diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2022-9-19\347\254\254\344\270\211\346\254\241\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2022-9-19\347\254\254\344\270\211\346\254\241\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..e5f302ea780363cea992f82956ddb245a943094d --- /dev/null +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-19\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2022-9-19\347\254\254\344\270\211\346\254\241\347\254\224\350\256\260.md" @@ -0,0 +1,11 @@ + - ROW_NUMBER()函数生成的排序根据排序子句给出**递增连续的序号** +- RANK()函数生成的排序根据排序子句给出**递增的序号,但是存在并列并且跳空** +- DENSE_RANK() 函数生成的排序根据排序子句给出**递增的序号,但是存在并列不跳空** + +```sql +ROW_NUMBER() over(order by 列名 desc)、 +-- select StuName 姓名,ROW_NUMBER() over(order by score desc) +rank() over(order by 列名 desc) +dense_rank() over(order by 列名 desc) +``` + diff --git a/README.en.md b/README.en.md deleted file mode 100644 index ac31e94d7051efb27325dd6be9b67641b85572e6..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# SQL进阶 - -#### Description -11 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 1c4b0e7c62868161068647925213862187205184..42b200cd173bad8a2ba441d8c1c19956e4d9cfdd 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,37 @@ -# SQL进阶 - -#### 介绍 -11 - -#### 软件架构 -软件架构说明 - - -#### 安装教程 - -1. xxxx -2. xxxx -3. xxxx - -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +# SQL进阶 + +#### 介绍 +11 + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 特技 + +1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md +2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) +3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 +4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 +5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) +6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git "a/\351\223\276\346\216\245" "b/\351\223\276\346\216\245" deleted file mode 100644 index 9531489de623cde3db375e5693d4473418d5b8c2..0000000000000000000000000000000000000000 --- "a/\351\223\276\346\216\245" +++ /dev/null @@ -1 +0,0 @@ -https://gitee.com/organizations/level-21-software-class-4/invite?invite=886e51af49d4c8e870217e863b9617a4db8ea8872269409fe67a7010cd42d36e1326d508fe5ad93be766b0d826817bc9 \ No newline at end of file