1. sql中的條件篩選!!!!
select id,sum(socre) as socre,type from A where type=17 group by id,type
union
select id,sum(socre) as socre,type from A where type<17 and type>12 and id not in (select id from A where type=17
) group by id,type
union
select id,sum(socre) as socre,type from A where type<13 and id not in (select id from A where type>12
) group by id,type
好久沒寫SQL語句了 水平不怎麼樣 寫的有點復雜 這樣行不?
2. 用SQL語句實現數據篩選
--將欄位條件篩選建立臨時表
selecttop100*
into#temp
fromtable
wherenamenotin("%批發%","不含'%廠")
andregionin("餐飲",..."副食")--填寫完每個經營面
--返回數據表,企業數和個體戶,這個區分不知道用什麼,所以第二個欄位還需要改
selectprovince,count(distinctname)asnum_company,
casewhenname="個體戶"thencount(distinctname)asnum_indivial
from#temp
3. SQL篩選記錄查詢語句
select * from tablename where 價格組<>'條件';
4. SQL多個條件篩選
1、創建測試表,create table test_con_x(company_name varchar(200), remark varchar2(200));
5. sql語句篩選
select*from(
select*,row_number()over()seqfrom[表A]
)twhereseq=1
6. Sql 對數據進行篩選 請問怎麼寫語句
--DROPTABLEtest
CREATETABLEtest(aINT,bINT,cVARCHAR(10))
INSERTINTOdbo.test
(a,b,c)
SELECT5038,1,'ss030001'
UNIONALL
SELECT
5038,1,'ss030001'
UNIONALL
SELECT
5038,2,''
UNIONALL
SELECT
5038,3,''
UNIONALL
SELECT
5038,2,'444'
UNIONALL
SELECT
5121,1,''
UNIONALL
SELECT
5038,3,'123456'
SELECT*FROMtestWHEREisnull(c,'')<>''
UNIONall
SELECTa,b,c
FROM
(
SELECTROW_NUMBER()OVER(PARTITIONBYaORDERBYa)id,*
FROMtest)t1
WHEREid=1ANDaNOTIN(SELECTaFROMtestWHEREisnull(c,'')<>'')
結果:
5038 1 ss030001
5038 1 ss030001
5038 2 444
5038 3 123456
5121 1
7. SQL 篩選查詢+刪除
查找重復的記錄:
Select * From table_name Where email In (Select email From table_name where inputdate between 'starttime' and 'endtime' Group By email Having Count(*)>1)
and inputdate between 'starttime' and 'endtime'
刪除重復的記錄:
情況1:刪除所有重復的記錄
delete table_name Where email In (Select email From table_name where inputdate between 'starttime' and 'endtime' Group By email Having Count(*)>1)
and inputdate between 'starttime' and 'endtime'
情況2:刪除重復記錄中的部分記錄,只保留重復記錄中的最早時間的那條記錄
delete a from table_name a Where not exists (Select 1 From table_name b where b.inputdate between 'starttime' and 'endtime' and b.email=a.email and b.inputdate<a.inputdate)
and a.inputdate between 'starttime' and 'endtime'
8. 一張表 如何用sql語句進行篩選
使用distinct 去掉重復數據 後面跟什麼欄位 就是去掉什麼重復的 多個欄位用,隔開
例如 Select distinct name from a ;
得到的結果就是 張三 ,李四
9. 用sql語句進行篩選
select姓名from表where課程!='A'
10. SQL資料庫的select篩選—【小白求教】!!
select * from 表名 where ziliao='nan'