UPDATE expense_order as a left join ( SELECT detail.company_id,detail.`order_id`,sum(detail.`deduction_money`) as amount FROM expense_amortize_detail as detail JOIN `pigcms_expense_order` as expense on expense.`id` = detail.`order_id` WHERE detail.`company_id` =336 and detail.`status` = 0 and expense.`company_id` =336 and expense.type=2 and expense.is_parent = 1 and expense.status in (1,2) and expense.auditing_status = 1 GROUP BY(expense.`id`) ORDER BY expense.`id` DESC ) as d on a.id =d.order_id and a.company_id = d.company_id and a.type =2 set a.settlement_money=d.amount;
UPDATE expense_order as a left join expense_order_bak as bak on a.id =bak.id set a.settlement_money=bak.settlement_money where a.type=1
UPDATE expense_order as a inner join ( SELECT detail.company_id,detail.`order_id`,sum(detail.`deduction_money`) as amount FROM expense_amortize_detail as detail JOIN `pigcms_expense_order` as expense on expense.`id` = detail.`order_id` WHERE detail.`company_id` =336 and detail.`status` = 0 and expense.`company_id` =336 and expense.type=2 and expense.is_parent = 1 and expense.status in (1,2) and expense.auditing_status = 1 GROUP BY(expense.`id`) ORDER BY expense.`id` DESC ) as d on a.id =d.order_id and a.company_id = d.company_id and a.type =2 set a.settlement_money=d.amount;
-- 删除blog库 DROP DATABASE IF EXISTS blog; -- 新建blog库 CREATE DATABASE blog charset utf8; -- 查看、进入 show database; use blog; -- 先删后建栏目表 drop table if exists blog_cate ; create table blog_cate ( id INTEGER, catename varchar(30) ); -- 同理 建文章表blog_artcle --- 插入数据 INSERT INTO `blog_cate `(`id`, `catename `) VALUES (1, '父亲的散文诗'); INSERT INTO `blog_cate `(`id`, `catename `) VALUES (2, '心情文字'); INSERT INTO `blog_artcle`(`id`, `title`, `desc`, `content`, `cateid`, `time`, `pic`) VALUES (1, 'test', '测试测试', '父亲的散文诗', 1, 2022, 'dd'); INSERT INTO `blog_artcle`(`id`, `title`, `desc`, `content`, `cateid`, `time`, `pic`) VALUES (2, 'test1', '测试测试1', '父亲的散文诗1', 1, 2022, 'dd'); INSERT INTO `blog_artcle`(`id`, `title`, `desc`, `content`, `cateid`, `time`, `pic`) VALUES (4, 'test4', '测试测试4', '父亲的sf散文诗1', 2, 2022, 'dd'); INSERT INTO `blog_artcle`(`id`, `title`, `desc`, `content`, `cateid`, `time`, `pic`) VALUES (3, 'test3', '测试测试3', 'dfsfsfs', 2, 2022, 'dd');
查询的是两张表的并集,也就是A表和B表都必须有数据才能查询出来;
/*** 栏目的id 与 文章的所属栏目id */ -- join select * from blog_cate as c join blog_artcle as a on c.id = a.cateid -- inner join select * from blog_cate as c inner join blog_artcle as a on c.id = a.cateid -- 逗号的连表方式就是内连接 select * from blog_cate as c, blog_artcle as a where c.id = a.cateid /**栏目的id 与 文章的id 进行查询*/ select * from blog_cate as c inner join blog_artcle as a on c.id = a.id
是以左表为基础,根据ON后给出的两表的条件将两表连接起来。结果会将左表所有的查询信息列出,而右表只列出ON后条件与左表满足的部分。左连接全称为左外连接,是外连接的一种。
/*** 栏目的id 与 文章的id */ -- left join select * from blog_cate as c left join blog_artcle as a on c.id = a.id -- left outer join select * from blog_artcle as c left outer join blog_cate as a on c.id = a.id
是以右表为基础,根据ON后给出的两表的条件将两表连接起来。结果会将右表所有的查询信息列出,而左表只列出ON后条件与右表满足的部分。右连接全称为右外连接,是外连接的一种。
-- right join select * from blog_cate as c right join blog_artcle as a on c.id = a.id -- right outer join select * from blog_artcle as c right outer join blog_cate as a on a.id = c.id
全连接显示两侧表中所有满足检索条件的行。
mysql中没有full join,mysql可以使用union实现全连接;
select * from blog_cate as c left join blog_artcle as a on a.id = c.id union select * from blog_cate as c right join blog_artcle as a on c.id = a.cateid
-- 修改文章cateid 为2的内容 为所属栏目的name UPDATE blog_artcle as a LEFT JOIN blog_cate as c on a.cateid = c.id and a.cateid = 2 SET a.content = c.catename
SELECT * FROM blog_artcle
--- left join 与 where 结合 改cateid =2 的 UPDATE blog_artcle as a LEFT JOIN blog_cate as c on c.id = a.cateid SET a.content = c.catename WHERE a.cateid = 2 --- inner join 与on 结合 改cateid =1 的 UPDATE blog_artcle as a inner JOIN blog_cate as c on a.cateid = c.id and a.cateid =1 SET a.content = c.catename