t_a 字段如下
t_b
t_his_a
/*查询*/
//1
select * from t_a;
//2
select a.name from t_a a where a.id = 2;
select 姓氏.name from t_a 姓氏 where 姓氏.id = 2;
select 姓氏.id "编号",姓氏.name as "姓名" from t_a 姓氏 where 姓氏.id = 2;
///3
select distinct a.name from t_a a;
select distinct a.name,a.remark from t_a a;
select a.name,a.remark from t_a a group by name;
///4排序
select a.* from t_a a order by a.name;
///合并
select b.depart,b.id,b.name, a.remark from t_a a,t_b b where a.id = b.id;
select * from t_a a left join t_b b on a.id = b.id;
select * from t_b b left join t_a a on a.id = b.id;
///范围
select * from t_a a where a.id between 1 and 3;
select * from t_a a where (a.id between 1 and 3) and a.name = "钱";
/*插入数据库数据*/
insert into t_a(id,name)values (4,"李");
///2.1
insert into t_his_a (tradingDay,id,name) select "20150112" as tradingDay ,a.id,a.name from t_a a;
/*更新*/
update t_a set name="金" where id =4;
update t_b set name =(select a.name from t_a a);
update t_b set t_b.name =(select name from t_a where t_a.id = t_b.id);
/*删除*/
delete from t_a where id = 4;