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.

本文详细介绍SQL的基本操作,包括创建数据库和表,插入数据,以及如何使用SELECT语句进行数据查询。示例展示了如何筛选特定条件的数据,按字段排序,以及进行聚合函数如COUNT, SUM, MAX, AVG的操作。
972

被折叠的 条评论
为什么被折叠?



