sql语句博大精深 理解好sql语句,就能用好thinkphp等框架中的数据库操作 原sql SELECT a.*,b.* from (SELECT a.id as opener_id,a.name,sum(c.money) as bonus_money,c.year,c.month from sh_opener a LEFT JOIN sh_opener_bonus b on a.id = b.opener_id LEFT JOIN sh_incentive c on b.incentive_…
MySQL多表查询合并结果和内连接查询 1.使用union和union all合并两个查询结果:select 字段名 from tablename1 union select 字段名 from tablename2: 注意这个操作必须保证两张表字段相同,字段数据类型也相同,再针对结果统一排序操作等.另外,使用union的时候会去除重复(相同)的记录?,而union all则不会. create table table_new select * from ( SELECT * FROM DB.…
一.需求 用户答题,共3道,必须3题都答完才能提交. 目的:要查询用户答对了几题,答错了几题.(当然此处可以只查答对的题目数,用3减即得答错题的题目数) 二.sql select * ) rightCount from (select * from (select * from mic_td_exercise_push_problem mp order by mp.create_time desc) ) t1 ), () wrongCount from (select * from (selec…