专业网络服务提供商
关于进一步加强国内域名注册信
信产部、公安部全面开展依法打
“感恩回报,传递激情” —书生
关于2009年春节期间公司有关活
关于总部基地机房升级断网通知
关于网通服务器迁址的紧急通知
国研IDC机房进行设备升级割接通
关于上调中文域名注册和续费价
英文CN域名规则调整通知
关于部份服务器升级南北双通服
首页帮助中心数据库正文

MySQL SQL 语法参考


select count (*)
from table_name
where column_name = xxx

说明:
查询符合条件的资料共有几笔。
select sum(column1)
from table_name

说明:
1.计算出总和,所选的栏位必须是可数的数字形态。
2.除此以外还有 avg() 是计算平均、max()、min()计算最大最小值的整合性查询。
select column1,avg(column2)
from table_name
group by column1
having avg(column2) > xxx

说明:
1.group by: 以column1 为一组计算 column2 的平均值必须和 avg、sum等整合性查询的关键字
一起使用。
2.having : 必须和 group by 一起使用作为整合性的限制。

复合性的查询
select *
from table_name1
where exists (
select *
from table_name2
where conditions )

说明:
1.where 的 conditions 可以是另外一个的 query。
2.exists 在此是指存在与否。
select *
from table_name1
where column1 in (
select column1
from table_name2
where conditions )

说明: 
1. in 後面接的是一个集合,表示column1 存在集合里面。
2. select 出来的资料形态必须符合 column1。

其他查询
select *
from table_name1
where column1 like 'x%'

说明:like 必须和後面的'x%' 相呼应表示以 x为开头的字串。
select *
from table_name1
where column1 in ('xxx','yyy',..)

说明:in 後面接的是一个集合,表示column1 存在集合里面。
select *
from table_name1
where column1 between xx and yy

说明:between 表示 column1 的值介於 xx 和 yy 之间。

3、更改资料:
update table_name
set column1='xxx'
where conditoins

说明:
1.更改某个栏位设定其值为'xxx'。
2.conditions 是所要符合的条件、若没有 where 则整个 table 的那个栏位都会全部被更改。

4、删除资料:
delete from table_name
where conditions

说明:删除符合条件的资料。

说明:关于where条件后面如果包含有日期的比较,不同数据库有不同的表达式。具体如下:
(1)如果是access数据库,则为:where mydate>#2000-01-01#
(2)如果是oracle数据库,则为:where mydate>cast('2000-01-01' as date)
或:where mydate>to_date('2000-01-01','yyyy-mm-dd')
在delphi中写成:
thedate='2000-01-01';
query1.sql.add('select * from abc where mydate>cast('+''''+thedate+''''+' as date)');

如果比较日期时间型,则为:
where mydatetime>to_date('2000-01-01 10:00:01','yyyy-mm-dd hh24:mi:ss');

本新闻共2页,当前在第2页  1  2  

Copyright © 2000 - 2008 北京贰度网络科技发展有限公司 Morecn.Inc
《中华人民共和国电信与信息服务业务经营许可证》编号:京ICP证05007082号