sql

结构化查询语言

基本语法

select

group

SELECT `code`, COUNT(*) AS `total` FROM `log` WHERE `create_time` > 0 GROUP BY `code`
SELECT `code`, SUM(`money`) AS `money` FROM `log` WHERE `create_time` > 0 GROUP BY `code`

replace

replace into 跟 insert 功能类似,不同点在于:replace into 首先尝试插入数据到表中。

如果发现表中已经有此行数据(根据主键或者唯一索引判断)则先删除此行数据,然后插入新的数据。否则,直接插入新数据。

replace into tbl_name set col_name=value, 

alter

修改表结构

ALTER TABLE `user`
ADD `sign_type` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '签约类型' AFTER `type`,
ADD `account_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '后台修改者id' AFTER `weight`,
CHANGE `weight` `weight` bigint(20) unsigned NOT NULL DEFAULT '1' COMMENT '用户权重' AFTER `audit_data`;


常用语句

参见

参考资料