比较同一表格的两列中的字符串

时间:2019-08-02 02:31:20

标签: sql postgresql

我有以下数据-

Code1   Code2
G01621  E04621

我想显示在代码1中但不在代码2中的所有代码。

我编写了以下SQL,但返回的数据不正确-

select * from codes c1
left join codes c2 
on lower(c1.code1) = lower(c2.code2)
where c2.code2 is null

3 个答案:

答案 0 :(得分:1)

您可以使用not exists

select c.code1
from codes c
where not exists (select 1
                  from codes c2
                  where lower(c2.code2) = lower(c.code1)
                 );

答案 1 :(得分:0)

使用trim()函数

select * from codes c1
left join codes c2 
on trim(lower(c1.code1)) = trim(lower(c2.code2))
where c2.code1 is null;

Demo

答案 2 :(得分:0)

使用var video = document.querySelector("#cameraVideo"); var mode = "rear"; var mediaRecorder; var chunks = []; if (navigator.mediaDevices.getUserMedia) { navigator.mediaDevices.getUserMedia({video: { facingMode: "environment" } }).then(function (stream) { video.srcObject = stream; mediaRecorder = new MediaRecorder(stream); }).catch(function (err0r) { alert("Something went wrong!"); }); } $(".camera").find(".take").on("touchstart mousedown", function() { mediaRecorder.start(); mediaRecorder.ondataavailable = function(ev) { chunks.push(ev.data); } }); $(".camera").find(".take").on("touchend mouseup", function() { mediaRecorder.stop(); mediaRecorder.onstop = (ev)=>{ var blob = new Blob(chunks, { 'type' : 'video/mp4' }); chunks = []; var videoURL = webkitURL.createObjectURL(blob); if(video.srcObject) video.srcObject.getTracks().forEach(t => t.stop()); var reader = new FileReader(); reader.readAsDataURL(blob); reader.onloadend = function() { document.getElementById("savevideo").src = reader.result; document.getElementById("savevideo").play(); } } });

except