⑴ sql語句如何比較同一行的兩列數據大小
作為過濾條件,返回A列大於B列的所有記錄:
Select*From表WhereA>b
作為輸出,輸入A列與B列中較大的值:
SelectCaseWhenA>BThenAElseBEndAs列名From表
⑵ SQL 列比較
最安全還要加一個distinct,防止出現3 1 3 1 3 1這樣
SELECT 學號
FROM B
WHERE 編號 IN (SELECT 編號 FROM A WHERE 學號= 1)
GROUP BY 學號 HAVING COUNT(distinct 編號) >=3
count 裡面加了distinct肯定可以的,最後這個就是防止出現你補充的那種情況的
⑶ SQL 如何比較兩個表中的某一列
明顯不是空集嘛,比如表A和表B,某列有三個內容是1,2,3,復制完之後依然是某列為1,2,3,雖然是選擇你是想1<>1,2<>2,3<>3,但是你沒考慮到1<>2,1<>3,2<>3,這三種情況!
又沒規定第一行在單一條件下對應第一行!(加個反序就變成了3,2,1,3變成了第一行)
⑷ sql中如何比較某一列的大小
當languge、songname singer 相同時比較cool002的大小將小的那一列保存到另一張表中。
insert into another_table
select a.* from tablename a,
(select languger,songname singer ,min(cool002) cool002 from tablename group by languger,songname ,singer) b
where a.language=b.language
and a.songname = b.songname
and a.singer = b.singer
and a.cool002=b.cool002 ;
-- 原表中刪除較小的
delete tablename
where (language, songname , singer, cool002)
in (
select languger,songname ,singer , min(cool002) cool002
from tablename
group by language, songname , singer
having count(*)>=2
)
⑸ sql中如何比較某一列的大小
當languge、songname
singer
相同時比較cool002的大小將小的那一列保存到另一張表中。
insert
into
another_table
select
a.*
from
tablename
a,
(select
languger,songname
singer
,min(cool002)
cool002
from
tablename
group
by
languger,songname
,singer)
b
where
a.language=b.language
and
a.songname
=
b.songname
and
a.singer
=
b.singer
and
a.cool002=b.cool002
;
--
原表中刪除較小的
delete
tablename
where
(language,
songname
,
singer,
cool002)
in
(
select
languger,songname
,singer
,
min(cool002)
cool002
from
tablename
group
by
language,
songname
,
singer
having
count(*)>=2
)
⑹ SQL中兩列的比較
SELECTid,plicateID
FROMdbo.test
WHEREplicateIDNOTIN(SELECTidFROMtest)
UNIONALL
SELECTid,plicateID
FROMdbo.test
WHEREISNULL(plicateID,'')=''
----結果
100 99
102 NULL
103 NULL
你實際換下表名就可以了
⑺ SQL中如何對比兩張表中某列的所有數據
SELECT表C.列1列1,表A.列2列2,表B.列2列3
FROM(SELECT列1FROM表A
UNION
SELECT列1FROM表B)表C
LEFTJOIN表AON表A.列1=表C.列1
LEFTJOIN表BON表B.列1=表C.列1
⑻ 用SQL語言比較兩列的順序
如果按第一列排序是:
第一列 第二列
1 A
2 B
3 D
4 C
5 E
按第二列排序是:
第一列 第二列
1 A
2 B
4 C
3 D
5 E
二者當然不一樣
你說把 4 C這行數據提出來 是查詢時過濾掉還是直接將源數據的這一列給刪掉?
如果是過濾掉這行數據 查詢時加個條件就可以了
select * from 表名 where 第一列=4 and 第二列='C' order by 第一列
如果是想刪掉直接 delete 表名 where 第一列=4 and 第二列='C'
【註:如果第一列是字元串類型的話 第一列='4'】
⑼ sql語句 兩列對比找不同
select A列
from 表1
where A列 not in (
select A列
from 表2
)
union
select A列
from 表2
where A列 not in (
select A列
from 表1
)
⑽ 使用SQL語句比較兩個日期列的大小
日期就是一個實數,整數部分就是今天距1900-01-01那天的天數。小數部分表部時間
小時數=24*小數部分。 select
cast('1900-01-01
00:00:00.000'
as
datetime)
+
1.1
結果為1900-01-02
02:24:00.000 所以,直接比較大小就行了(where 日期欄位1
>
日期欄位1)。