常用sql命令

--1) 创建一张学生表,包含以下信息,学号,姓名,年龄,性别,家庭住址,联系 电话
CREATE TABLE student
(
    [id] [int] IDENTITY(1,1) NOT NULL,
    [student_id] [nvarchar](50)  NULL,
    [studen_name] [nvarchar](50) NULL,
    [age] [int] NULL ,
    [sex] [nvarchar](5) NULL,
    [address] [nvarchar](200) NULL,
    [tel] [nvarchar](20) NULL
)
 
--2) 修改学生表的结构,添加一列信息,学历 education
alter table student add education nvarchar(10) NULL
 
--3) 修改学生表的结构,删除一列信息,家庭住址
alter table student drop column address
 
--5) 修改学生表的数据,将电话号码以11开头的学员的学历改为“大专”
 
update student set education='大专' where tel like '11%'
 
--6) 删除学生表的数据,姓名以C开头,性别为‘男’的记录删除
 
delete student where studen_name like 'C%' and sex='男' 
 
--7) 查询学生表的数据,将所有年龄小于22岁的,学历为“大专”的,学生的姓名和学号示出来
select studen_name,student_id from student
where age<12 and education='大专'
 
--8) 查询学生表的数据,查询所有信息,列出前25%的记录
select TOP 25 PERCENT * from student
 
--9) 查询出所有学生的姓名,性别,年龄降序排列
select studen_name,sex,age from studen order by age desc
 
--10) 按照性别分组查询所有的平均年龄
 
select avg(age) as age from studen group by sex

转载于:https://www.cnblogs.com/nfyy/p/4380838.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值