select concat(a.id,'@col1') from a inner join b on a.id=b.id and a.col1<>b.col2
uj5u.com熱心網友回復:
大佬我是菜鳥,謝謝您的指導,但是能寫詳細一點嗎哈哈,我還是c++實習生,這個不太懂
uj5u.com熱心網友回復:
比較相同欄位就好了,不比較的欄位就忽略不計啊
uj5u.com熱心網友回復:
大佬我知道邏輯,就是sql這個怎么寫哈哈
uj5u.com熱心網友回復:
把你兩個表的表結構發出來,我寫SQL陳述句給你
uj5u.com熱心網友回復:
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score)
回傳的就是不同的id
uj5u.com熱心網友回復:
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score)
回傳的就是不同的id
uj5u.com熱心網友回復:
效率肯定高不了,可以考慮一下Minus。
uj5u.com熱心網友回復:
比較相同欄位就好了,不比較的欄位就忽略不計啊
大佬我知道邏輯,就是sql這個怎么寫哈哈
把你兩個表的表結構發出來,我寫SQL陳述句給你
大佬,就是不知道表結構,但是他們表結構相同
uj5u.com熱心網友回復:
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score)
回傳的就是不同的id
大佬需要用存盤函式寫,回傳的是字串那種
uj5u.com熱心網友回復:
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score)
回傳的就是不同的id
大佬需要用存盤函式寫,回傳的是字串那種
存盤程序不能回傳值的;
可以創建函式;
呼叫函式即可;
陳述句如下
DELIMITER $$
CREATE FUNCTION `idunion`() RETURNS varchar(200) CHARSET utf8mb4
BEGIN
set @idunion:=0;
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score) into @idunion;
return @idunion;
END$$
DELIMITER ;
select idunion();
uj5u.com熱心網友回復:
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score)
回傳的就是不同的id
大佬需要用存盤函式寫,回傳的是字串那種
存盤程序不能回傳值的;
可以創建函式;
呼叫函式即可;
陳述句如下
DELIMITER $$
CREATE FUNCTION `idunion`() RETURNS varchar(200) CHARSET utf8mb4
BEGIN
set @idunion:=0;
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score) into @idunion;
return @idunion;
END$$
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score)
回傳的就是不同的id
大佬需要用存盤函式寫,回傳的是字串那種
存盤程序不能回傳值的;
可以創建函式;
呼叫函式即可;
陳述句如下
DELIMITER $$
CREATE FUNCTION `idunion`() RETURNS varchar(200) CHARSET utf8mb4
BEGIN
set @idunion:=0;
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score) into @idunion;
return @idunion;
END$$
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score)
回傳的就是不同的id
大佬需要用存盤函式寫,回傳的是字串那種
存盤程序不能回傳值的;
可以創建函式;
呼叫函式即可;
陳述句如下
DELIMITER $$
CREATE FUNCTION `idunion`() RETURNS varchar(200) CHARSET utf8mb4
BEGIN
set @idunion:=0;
select GROUP_CONCAT(a.id SEPARATOR '@') as diff_ids
from tests01_des02 as a inner join tests01_des as b
on a.id=b.id
and (a.name1<>b.name1 or a.score<>b.score) into @idunion;
return @idunion;
END$$
create table a1(id int,allcol varchar(500));
insert into a1(id)
select id from (
select * from tests01_des02
union
select * from tests01_des) as a
group by id
having count(1)>1;
call getdiffcol();
存盤程序代碼;
CREATE PROCEDURE `getdiffcol`()
begin
declare allcol1 varchar(500);
declare id1 int;
declare done INT DEFAULT 0;
declare cur_test cursor for select id from a1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
open cur_test;
repeat
fetch cur_test into id1;
set allcol1 ='name1@score';
if not done then
begin
if (select name1 from tests01_des02 where id=id1)=(select name1 from tests01_des where id=id1) then
set allcol1=replace(allcol1,'name1','');
end if;
if (select score from tests01_des02 where id=id1)=(select score from tests01_des where id=id1) then
set allcol1=replace(allcol1,'@score','');
end if;
update a1 set allcol=allcol1 where id=id1;
end;
end if;
until done end repeat;
close cur_test;
update a1 set allcol=case when left(allcol,1)='@' then right(allcol,length(allcol)-1) else allcol end;
update a1 set allcol=concat(id,'@',allcol) ;
select group_concat(allcol SEPARATOR '|') as result from a1 ;
END
create table a1(id int,allcol varchar(500));
insert into a1(id)
select id from (
select * from tests01_des02
union
select * from tests01_des) as a
group by id
having count(1)>1;
call getdiffcol();
存盤程序代碼;
CREATE PROCEDURE `getdiffcol`()
begin
declare allcol1 varchar(500);
declare id1 int;
declare done INT DEFAULT 0;
declare cur_test cursor for select id from a1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
open cur_test;
repeat
fetch cur_test into id1;
set allcol1 ='name1@score';
if not done then
begin
if (select name1 from tests01_des02 where id=id1)=(select name1 from tests01_des where id=id1) then
set allcol1=replace(allcol1,'name1','');
end if;
if (select score from tests01_des02 where id=id1)=(select score from tests01_des where id=id1) then
set allcol1=replace(allcol1,'@score','');
end if;
update a1 set allcol=allcol1 where id=id1;
end;
end if;
until done end repeat;
close cur_test;
update a1 set allcol=case when left(allcol,1)='@' then right(allcol,length(allcol)-1) else allcol end;
update a1 set allcol=concat(id,'@',allcol) ;
select group_concat(allcol SEPARATOR '|') as result from a1 ;
END
create table a1(id int,allcol varchar(500));
insert into a1(id)
select id from (
select * from tests01_des02
union
select * from tests01_des) as a
group by id
having count(1)>1;
call getdiffcol();
存盤程序代碼;
CREATE PROCEDURE `getdiffcol`()
begin
declare allcol1 varchar(500);
declare id1 int;
declare done INT DEFAULT 0;
declare cur_test cursor for select id from a1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
open cur_test;
repeat
fetch cur_test into id1;
set allcol1 ='name1@score';
if not done then
begin
if (select name1 from tests01_des02 where id=id1)=(select name1 from tests01_des where id=id1) then
set allcol1=replace(allcol1,'name1','');
end if;
if (select score from tests01_des02 where id=id1)=(select score from tests01_des where id=id1) then
set allcol1=replace(allcol1,'@score','');
end if;
update a1 set allcol=allcol1 where id=id1;
end;
end if;
until done end repeat;
close cur_test;
update a1 set allcol=case when left(allcol,1)='@' then right(allcol,length(allcol)-1) else allcol end;
update a1 set allcol=concat(id,'@',allcol) ;
select group_concat(allcol SEPARATOR '|') as result from a1 ;
END
**桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......
我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......
關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......