SQL 將多個通過篩選得到的資料相加

2021-10-07 03:30:49 字數 1427 閱讀 5033

資料庫的表,對這張表進行查詢、篩選等操作

pwr_1>0同時pwr_2>pwr_1,將pwr的和輸出。值578

select

case

when

sum(pwr)

isnot

null

then

sum(pwr)

else

0end

from dbo.test

where pwr_1>=

0and pwr_2>pwr_1

pwr_2<=pwr_1 ,將pwr除以2之後合併。值742

select

case

when

sum(pwr)

isnot

null

then

sum(pwr/2)

else

0end

from dbo.test

where pwr_2<=pwr_1

pwr_1<0 。值0

select

case

when

sum(pwr)

isnot

null

then

0else

0end

from dbo.test

where pwr_1<

0

將篩選出來的值相加。值1320

select

(select

case

when

sum(pwr)

isnot

null

then

sum(pwr)

else

0end

from dbo.test

where pwr_1>=

0and pwr_2>pwr_1)+(

select

case

when

sum(pwr)

isnot

null

then

sum(pwr/2)

else

0end

from dbo.test

where pwr_2<=pwr_1)+(

select

case

when

sum(pwr)

isnot

null

then

0else

0end

from dbo.test

where pwr_1<

0)

通過shell將乙個檔案劃分為多個檔案

原始檔名為test.xt,檔案內容如下 sort a 3 4 sort a 2 5 sort b 1 2 sort b 2 5 分割後的檔案 file1 sort a 3 4 sort a 2 5 file2 sort b 1 2 sort b 2 5 這個其實很簡單,就是遍歷每一行的時候,在把該行...

通過sql語句將Excel表匯入資料庫

將資料匯入到臨時表 packageinfo裡面 select into packageinfo from openrowset microsoft.jet.oledb.4.0 excel 5.0 hdr yes database g packageinfo.xls sheet1 將臨時表裡面的資料匯...

sql 查詢多個表

直接黏貼sql cook book上的資料 1 select ename as ename and dname,deptno 2 from emp 3 where deptno 10 4 union all 5 select null 6 from t1 7 union all 8 select d...