SQL(Structed Query Language)
<一>建数据库
create database test; //创建名为test数据库
use test;
<二>建表
create table student(s_id int primary key, s_name varchar(20)); //在test数据库下创建名为student的表 insert into student values(1, 'Jack'); insert into student values(2, 'Rithvik'); insert into student values(3, 'Jaspreet'); insert into student values(4, 'Praveen'); insert into student values(5, 'Bisa'); insert into student values(6, 'Suraj');
效果图:
<三>查询
Data Query Language:
- SELECT [DISTINCT] Attribute_List FROM R1,R2….RM
- [WHERE condition]
- [GROUP BY (Attributes)[HAVING condition]]
- [ORDER BY(Attributes)[DESC]];
举例说明:
select s_id,s_name from student where s_id>2; //output the table in a way [where ....]
效果图:
select * from marks; //marks is the table name
select score from marks order by score; //order according to score
select score from marks order by score desc;
select min(score) from marks;
[注]: In the same way, COUNT, SUM, MAX and AVG can be used.
select distinct status from marks; //remove the same attributes
select sum(score), status from marks group by status;
[注] group by is used to group the tuples of a relation based on an attribute(status) or group of attribute.