Sql

来自lfzyx
跳转至: 导航搜索
  • select
select [column1,column2..] 
from table1,table2 
[where column1 = | > | < | > = | < | != | is [not] null | in | not in | like | or | and]
[group by column1,column2 having] 
[order by column1 desc, column2 asc]; 

示例:

select name, course_id from section where semester = 'Fall' and year = 2009 and member_id in (select member_id from account where money > 2000);
select count(distinct course_id) from section where (year,member_id) in (select year, member_id from account where money > 2000);
select name from section where money > some(select money from section where year = 2009);
select name from section where money > all(select money from section where year = 2009);
select M.`member_id`, mobile, available_money as money, locked_money FROM `member` as M,`member_accout` as A where M.member_id = A.member_id  order by available_money desc,  mobile asc ;
select sum(available_money), `acct_type` from member_accout group by acct_type having sum(available_money) > 231782.5000 order by sum(available_money);
  • grant
grant [privileges] on [column or view] to [user]

示例:

 grant select on test to U1,U2
  • revoke
revoke [privileges] on [column or view] from [user]

权限列表:

select 读权限
insert 插入权限
update 修改权限
delete 删除权限
references 声明外键的权限
all privileges  所有权限
grant option 转授权限 

show create database db_name;

show create table tbl_name;[1]

复合索引

参考文献[编辑]

  1. MySQL字符集乱码总结