显示表的列:show columns from sometable; 或 describe sometable;
查看创建表的语句:show create table sometable;
限制查询返回的开始行和行数:select somecolumn from sometable limit 3 offest 5;
查询某个列取值在5和10之间的行:select somecolumn_a, somecolumn_b from sometable where somecolumn_b between 5 and 10;
查询某个列取值在某个集合内的行:select somecolumn_a, somecolumn_b from sometable where somecolumn_b in (3, 5, 7);
下划线匹配单个任意字符:select * from sometable where somecolumn like '_test';
尽量不要把通配符置于搜索模式的开始处
REGEXP正则匹配默认不区分大小写,要区分大小写,可使用BINARY关键字:select somecolumn_a from sometable where somecolumn_b REGEXP BINARY ‘abc .999’;
日期比较:select * from sometable where Date(somedate) between ‘2011-07-01’ and ‘2011-09-30’;
过滤分组:select cust_id count( * ) as orders from ordertable group by cust_id having count( * ) >= 2 ;
没有评论:
发表评论