当前位置:Gxlcms > 数据库问题 > SqlSever基础 where 与 group by组合起来 处理数据

SqlSever基础 where 与 group by组合起来 处理数据

时间:2021-07-01 10:21:17 帮助过:19人阅读

use master 2 drop database helloworld 3 4 5 --创建一个数据库 6 create database helloworld 7 8 9 10 --用helloworld1这个数据库 11 use helloworld 12 13 --创建一个表格teacher 14 create table Teacher 15 ( 16 Id int primary key identity(1,1), 17 Name nvarchar(10), 18 Class nchar(2), 19 score float 20 ) 21 22 create table Location 23 ( 24 Class nchar(2), 25 location nvarchar(5) 26 ) 27 28 --看看 teacher这个表格有啥 29 select * from Teacher 30 select * from Location 31 32 --向这个Teacher中插入这几行内容,这个内容我插入一遍后,简单修改,又插入一遍 33 insert into Teacher 34 values(燃灯古佛,佛家,100), 35 (释迦摩尼佛,佛家,100), 36 (弥勒佛,佛家,100), 37 (释迦摩尼佛,佛家,100), 38 (女娲娘娘,道家,100), 39 (文殊菩萨,佛家,100), 40 (普贤菩萨,佛家,101), --为了方便,给普贤菩萨加1分 41 (阳明贪狼太星君,道家,101), 42 (阴精巨门元星君,道家,101), 43 (真人禄存真星君,道家,101), 44 (玄冥文曲纽星君,道家,101) 45 46 --向这个Location中插入这几行内容 47 insert into Location 48 values(佛家,印度), 49 (道家,中国), 50 (基督,西方), 51 (儒家,中国) 52 53 --查看teacher表中有什么内容 54 select * from Teacher

 

 

2 table

技术分享

 

 

3 key code

1 --求取在teacher表中,存的,佛道两家 获得 100的 有多少
2 select Class,score,count(*) as num
3 from Teacher
4 where score=100
5 group by Class,score 

 

 

4 show

技术分享

 

 

 

——————————————————————————————————————————
博文的精髓,在技术部分,更在镇场一诗。
SqlSever是优秀的语言,值得努力学习。熟悉数据库的增删查改,写程序必备。
如果博文的内容有可以改进的地方,甚至有错误的地方,请留下评论,我一定努力改正,争取铸成一个良心博客。
注:此文仅作为科研学习,如果我无意中侵犯了您的权益,请务必及时告知,我会做出改正。

SqlSever基础 where 与 group by组合起来 处理数据

标签:一个数据库   creat   oca   方便   primary   sql   分享   har   增删查改   

人气教程排行