① 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中怎樣實現字元串大小的比較
sql裡面字元串沒有大小之分,只有長度之分,可以比較長度大小,但是想用一條sql語句直接拿到大小結果來說也不太方便,最好是藉助程序或者sql腳本來做,我用oracle試了下,用case when函數是可以直接比較大小的,比如第一個值比第二個大輸出0,否則輸出1:
select(casewhenlen1>len2then0whenlen1<len2then1end)asresfrom(
selectlength('asd')aslen1,length('as')aslen2fromal)t
③ sql 按百分比排序怎麼寫
select A1,,sum(case when a2=1 then 1 else 0 end)*1.0/count(1)as '1的百分比'
from Table
group by A1
④ sql中如何對多個欄位匯總後再比較大小
這樣嗎?
select x.* from (
select
*,
a + b +c as sum_abc
from tab
) as x order by x.sum_abc desc;
⑤ 使用sql語句計算百分比
1、若針對每行求百分比: select SA/TotelTime ,SB/TotelTime ,SC/TotelTime ,SD/TotelTime ,SE/TotelTime from 表名 。
2、若是對總計後的值求百分比: select sum(SA)/sum(TotelTime) ,sum(SB)/sum(TotelTime) ,sum(SC)/sum(TotelTime) ,sum(SD)/sum(TotelTime) ,sum(SE)/sum(TotelTime) from 表名
3、當然,以上都是以小數形式顯示結果,若要以百分比形式顯示結果:乘以100,並保留兩位小數,然後加上「%」即可。
如:round((SA/TotelTime)*100,2) & "%"
⑥ sql存儲過程中時分秒字元串怎麼比較大小 如08:30:00 與13:00:00怎麼比較
oracle 中字元串日期類型是可以直接比較的,如:
select * from scott.emp where '08:30:00'<'13:00:00'
但是如果你要用一張表中的時間欄位進行比較時,必須使用to_date()函數,如:
select * from scott.emp where hiredate<to_date('2012.01.01 13:00:00','yyyy.mm.dd hh24:mi:ss')
⑦ sql語句的大小比較
select case when A>B then A else B end,case when C>B then B else C end from table
⑧ SQL 兩個數字欄位比較大小
這個簡單,Where部分如下:where 物品數量>安全庫存這樣就行了,容易吧?
⑨ 資料庫中sql語句三個數比較大小怎麼做
declare @x int ,@y int ,@z int
set @x=33
set @y=666
set @z=55
if @x>@y
begin
if @x>@z
print @x
else
print @z
end
else
begin
if @y>@z
print @y
else
print @z
end
第二種
declare @x int ,@y int ,@z int,@max int
set @x=33
set @y=22
set @z=20
if @x>@y
set @max =@x
else
set @max =@y
if @max >@z
set @max=@max
else
set @max =@z
print @max