您的位置:首页 > 数据库

SQL语句学习

2016-03-28 21:45 337 查看
1.创建表

create table A (id int);

2.删除表

drop table A

3.添加数据

insert into A (id) values (1);

4.删除某一行内容

delete from A where id = 1

5.为表添加字段

alter table A add name varchar(10)

6.为表删除字段

alter table A drop name

7.查询名字为sam的人数

select count(*) from A where name = ‘sam’

8.查询学生,学生的科目数量

select name,count(subject) from A

9.查询学生,科目,成绩,先按照名字排列,再按成绩由高到低排列

SELECT name,subject,score from a ORDER BY name,score DESC

10.查询学生,成绩最高的科目,成绩(只差一条数据,即一个学生)

SELECT name,subject,max(score) from a

11.查询每个学生,成绩最高科目,成绩(每个学生)

SELECT name,subject,max(score) from a GROUP BY name
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: