一些常用的mysql语句
[color=brown][b]初始化自增长[/b][/color]
ALTER TABLE tablename auto_increment=1
[b][color=brown]判断表是否存在[/color][/b]
select table_name from `INFORMATION_SCHEMA`.`TABLES` where table_name = 'tablename'
查询表的枷锁解锁机制
show engines 查询数据库表机制
show table status like 'table_name' 查询table_name的机制
更新需要操作的数据
update pe_bzz_examscore s set s.total_grade = '不合格'
where s.id in (select t.id from (select id,fk_exam_batch_id,status,total_score from pe_bzz_examscore) t
where t.fk_exam_batch_id = '0000' and t.status = '111' and ifnull(t.total_score, 0) < 60)
动态的模糊查询
select * from table1 where `text` like CONCAT( '%' , (select name from table2 where id =1), '%' );
=---关联查询的重复处理 用left也不行的时候
//String sql = "select eo.order_id order_id,eo.sn sn,eo.create_time create_time,eo.member_id member_id from es_order eo,es_order_items eoi,es_goods eg where eo.order_id = eoi.order_id and eoi.goods_id=eg.goods_id and eg.is_fund_goods=1 and eo.pay_status=2 and eo.member_id="+member.getMember_id();
// 第一个不行 第二个可以
String sql = "SELECT eo.order_id order_id,eo.sn sn,eo.create_time create_time,eo.member_id member_id FROM es_order eo WHERE 1 = 1 AND eo.pay_status = 2 AND eo.member_id = ? AND EXISTS( SELECT 1 FROM es_order_items eoi WHERE 1 = 1 AND eo.order_id = eoi.order_id AND EXISTS(SELECT 1 FROM es_goods eg WHERE eoi.goods_id = eg.goods_id AND eg.is_fund_goods = 1) )";
// 上面处理是为了分页时候不能用group by的处理
[color=brown][b]初始化自增长[/b][/color]
ALTER TABLE tablename auto_increment=1
[b][color=brown]判断表是否存在[/color][/b]
select table_name from `INFORMATION_SCHEMA`.`TABLES` where table_name = 'tablename'
查询表的枷锁解锁机制
show engines 查询数据库表机制
show table status like 'table_name' 查询table_name的机制
更新需要操作的数据
update pe_bzz_examscore s set s.total_grade = '不合格'
where s.id in (select t.id from (select id,fk_exam_batch_id,status,total_score from pe_bzz_examscore) t
where t.fk_exam_batch_id = '0000' and t.status = '111' and ifnull(t.total_score, 0) < 60)
动态的模糊查询
select * from table1 where `text` like CONCAT( '%' , (select name from table2 where id =1), '%' );
=---关联查询的重复处理 用left也不行的时候
//String sql = "select eo.order_id order_id,eo.sn sn,eo.create_time create_time,eo.member_id member_id from es_order eo,es_order_items eoi,es_goods eg where eo.order_id = eoi.order_id and eoi.goods_id=eg.goods_id and eg.is_fund_goods=1 and eo.pay_status=2 and eo.member_id="+member.getMember_id();
// 第一个不行 第二个可以
String sql = "SELECT eo.order_id order_id,eo.sn sn,eo.create_time create_time,eo.member_id member_id FROM es_order eo WHERE 1 = 1 AND eo.pay_status = 2 AND eo.member_id = ? AND EXISTS( SELECT 1 FROM es_order_items eoi WHERE 1 = 1 AND eo.order_id = eoi.order_id AND EXISTS(SELECT 1 FROM es_goods eg WHERE eoi.goods_id = eg.goods_id AND eg.is_fund_goods = 1) )";
// 上面处理是为了分页时候不能用group by的处理