sqlserver按照某個欄位的值排序,但是需要剔除裡面某些值怎麼寫

2021-03-29 00:24:59 字數 6065 閱讀 4827

1樓:哈哈我結婚啦

在order by之前寫,where aaa<>2!不用謝我 我是雷鋒,這些都是最基礎的sql用法,你還需努力啊

2樓:匿名使用者

判斷條件加上aaa不等於2就可以了。

3樓:匿名使用者

select * from 表名 where aaa<>'2' order by aaa

sql 按欄位指定值排序

4樓:匿名使用者

這個需要在排序語句中使用條件判斷

例如:表【table_temp】中列【col1】為字元,屬性為varchar(10),排序時需要按照b、a、c的順序顯示,則可按照以下sql語句:

select

*from

table_temp

order by

case

when col1='b' then 1

when col1='a' then 2

when col1='c' then 3end

5樓:匿名使用者

在mssql支援case,使用以下語句實現select 表1.id, 表1.n

from 表1

order by case n when 'a2' then 1 when 'a1' then 2 when 'a3' then 3 end;

在access中使用iif來實現,如下:

select 表1.id, 表1.n

from 表1

order by iif(n='a2',1,iif(n='a3',2,3));

可參考access幫助檔案中的

access > 篩選和排序 > 按自定義次序對記錄排序

6樓:沉默使用者

order by 字句中使用case

select *

from table1

order by case a1 when 'a2' then 1 when 'a3' then 2 when 'a1' then 3 end

7樓:匿名使用者

你可以加上一個計算列,將它轉換成可排序的,比如在oracle中可依這樣

select table1.*,decode(table1.a1,'a2' ,1,'a3',2,'a1',3,0)xx from table1 order by xx

8樓:匿名使用者

select * from dbo.table1where a1= 'a1'

union

select * from dbo.table1where a1<> 'a1'

order by a1 desc試一下

9樓:匿名使用者

在select語句後面加上 order by a1 desc是降序

order by a1 asc是升序;

sql如何根據欄位內的某個值排序 5

10樓:

這個正規表示式就可以篩選出數字部分,但是每種資料庫用法都是不一樣的

再根據篩選出來的這個偽劣來排序就好了

11樓:

可以擷取後面的數字用著排序欄位

sql語句中,如何按指定欄位排序

12樓:塵緣

對於這種排序的問題處理,如果不是簡單中英文排序,最好**排序列,sortnum,起到排序的效果,複雜點如每個人有個自己的排序規則,可寫個對映表儲存每個人的排序規則,進行排序

13樓:匿名使用者

select * from table

order by case when ssdw2='上訴人' then 0 else 1 end

14樓:匿名使用者

用order by根據 反向則加上desc

select * from table order by case when ssdw2='上訴人' then 0 else 1 end

15樓:匿名使用者

select * from studens order by charindex(say,'上訴人',0) desc

sql語句刪除某個欄位的部分資料

16樓:匿名使用者

這個完全可以的。

update的語句格式:

update 表名稱 set 列名稱 = 新值 where 列名稱 = 某值

你這種用法:

專update qx_repair_items set qri_rman=replace(qri_rman,'/'+@spname,'') where qri_id=@mainid

的問題是:replace是vb的函屬數,而不是sql語句中的格式所允許的,應該這樣:

先用select * from qx_repair_items where qri_id=@mainid

通過一個變數,例如:x 讀取 qri_rman 欄位的值

然後 x = replace(x,'/'+@spname,'')

最後update qx_repair_items set qri_rman=x where qri_id=@mainid

我寫到這裡,突然想到,是否可以這樣:

"update qx_repair_items set qri_rman=" & replace(qri_rman,'/'+@spname,'') & " where qri_id=@mainid"

17樓:匿名使用者

oracle的話有replace函式

update一把表

18樓:儲存檔案

update md_equipment set city = '' where id = 'tzzx1907030008'

sql語句 刪除某欄位中一個資料

19樓:璋爺弒神

update 表名 set 欄位名=null where 欄位名=值 and 欄位2=值2;

值就是你要刪除的資料  欄位2和值2值是用來定位值在表中的具體位置 只有前面的值很容易刪除同欄位等值的數  加上欄位2值2就可以精準定位 值2最好是唯一約束下面這是我寫的

update student set 年齡=null where 年齡=21 and 學號=4002;

這個是隻用一個欄位的

這個用了欄位和主鍵 .看不懂多看幾遍.

20樓:匿名使用者

首先,你的說法是有問題的,不能刪除「某欄位中的一個資料」,而是刪除一條「記錄」

delete from表名 where 欄位=某值 --即刪除欄位為某值的所有記錄

如果你實際是想針對某個欄位的操作,那麼使用updateupdate 表名 set 欄位=null where 欄位=某值 --即將表中欄位為某值的替換為null

21樓:情又獨中

要刪一行的話,

delete from table where column='值';

要把這個欄位清的話

update table set column=null where column='值';

22樓:劉貴慶

delete 表 where 欄位=值

23樓:匿名使用者

這個就不叫刪除了,應該是update了,就是把你要刪的那個資料置空就好了

sql 先按一個欄位排序 然後再修改另一個欄位的值 怎麼弄呢

24樓:匿名使用者

1.order by 語句都抄

是放到sql語句的末尾的,襲所以bai想先排序就得用巢狀查詢或du者臨時表

zhi2.答題如這樣吧,dao

兩張表,a表(id,name),b表(id,demo)

sqlserver中:

update a set a.name = b.demo --這裡更新

from (select * from b order by id) b --這裡排序

join a on a.id = b.id

oracle 中:

update a set a.name = (select b.demo from (select * from b order by id) b where a.

id = b.id)

25樓:丁叮鈴

先獲取排序後的要修改的欄位,在修改此欄位

26樓:

update table set 欄位名 = '值' where 欄位名 = (select 欄位名 from table order by 欄位名 desc/asc limit 1)

sql查詢按指定欄位排序

27樓:匿名使用者

不知道你bai什麼資料庫

du, 假如是 oracle:

select

count(city_name),

city_name

from

tuan_info

where

source_type = 1

and city_name in("北京zhi","上海dao","廣州

內")group by

city_name

order by

instr('北京,上海,廣州', city_name);

如果是容 sql server 用

order by charindex(city_name, '北京,上海,廣州')

28樓:匿名使用者

醫病者父母心所說的

抄方法雖然可用,但非常的浪bai費時間,資料多了du,可能會有宕機的感覺.我看zhi不如這樣,修改資料表設計dao,增加一個小整數字段,位元組型也可,叫city_xh城市序號,當使用者輸入city_name時,用一個函式做以下工作如果輸入北京這個欄位的值就為1,如果上海就是2,如果重慶就25,如果臺北就31,把這個函式的值儲存到增加的欄位,排序的時候就按這個欄位排序.這不好嗎.

select count(city_xh),city_name from tuan_info where source_type = 1 and city_name in("北京","上海","廣州") group by city_name order by city_xh

可能資料表已經有資料了,開啟資料表,手工輸入,如果資料太多,就寫一過程,來填充這個欄位值.

29樓:小辰蛋

你能不能把具體的

來問題寫出來呢

源?一般都會有查詢的錯誤提示 錯誤**之類的.

感覺你寫的沒什麼問題呀,不過欄位值,應該用單引號,不是雙引號的.

select count(city_name),city_name from tuan_info where source_type = 1 and city_name in('北京','上海','廣州') group by city_name;

30樓:匿名使用者

select '北京

', count(city_name) from tuan_info where source_type = 1 and city_name ='北京'

union

select '上海

版, count(city_name) from tuan_info where source_type = 1 and city_name ='上海' union

select '廣州

權, count(city_name) from tuan_info where source_type = 1 and city_name ='廣州'

在oracle資料庫怎麼查詢某個欄位在哪些表中出現過

select table name from dba tab columns where column name 欄位名 大寫 從dba tab columns裡查詢 請問如何查詢一個oracle資料庫中,是否有某個表的某一列包含某個值 1 看使用者的表的資訊如同marliuang所說,不再贅述。當...

sql查詢除了某個欄位的值以外的其實記錄

select from 表名 where not 姓名 張三版 select from 表名 where 姓名 張三 select from 表名 where 姓名 not in 張三 李四 這些都可以權 select from tablename where name 張三 即查詢所有名字不等於張...

ecel查詢某一單元格是否含有某個欄位然後返回對

vlookup a2 資料表 b c,2,0 使用vlookup函式,假設表1的a列有名字,b列需要填入表2的b列相對應的c列的資料。vlookup a1,表2 b 1 c 4,2,false if countif 資料表 b b,a2 vlookup a2,資料表 b c,2,這個是精確查詢,要的...