SQL笔试题
左连接、右连接、内连接(等值连接)、全外连接
left join (左连接):返回包括左表中的所有记录和右表中连接字段相等的记录。right join (右连接):返回包括右表中的所有记录和左表中连接字段相等的记录。
inner join (内连接):只返回两个表中连接字段相等的记录。
full join (全外连接):返回左右表中所有的记录和左右表中连接字段相等的记录。
mysql根据一个时间字段查询在5分钟之内的数据:
select * from table_name where time >= now()-interval 5 minute;
关于索引:
// 查看索引
show index from tablename;
// 添加索引
alter table table_name add index index_name (table_column);
// 删除索引
drop index index_name on table table_name ;
alter table table_name drop index index_name ;
怎么查看数据库表中某个字段的值有哪些重复记录?
select
*
from
product
where
name
in
(
select
name
from
product
group
by
name
having
COUNT
(*)>1)
varchar char 和 text类型的区别:
varchar 和 char 都是字符类型。varchar为可变长类型,char为定长类型,定长类型通常用与固定长度类型的数据例如手机号等。定长的意义是例如设置长度20,只存储15位的数据,则取出时会取出15位+5位英文空格。
text 文本类型,比较占用磁盘空间,此类型的字段一般要么为空要么是长文本,能不用这种类型就不要用。
未完待续
从JPA转到了mybatis,目测这一篇可以更得频繁点了
。。。