SQL 语句 : 基础篇《一》

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:

  1. SELECT [DISTINCT] Attribute_List FROM R1,R2….RM
  2. [WHERE condition]
  3. [GROUP BY (Attributes)[HAVING condition]]
  4. [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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值