高分求助SQL語句寫法(t表中段中內容如 a,b,c,d。如何分別取出各值)

2021-07-07 04:14:41 字數 3152 閱讀 5739

1樓:匿名使用者

這個要用自定義函式了

比如象你的就是select split(欄位名,',',0) as 欄位1,split(欄位名,',',1) as 欄位2 ...

create function [dbo].[split]

(@str nvarchar(4000),@code varchar(10),@no int )

returns varchar(200)

asbegin

declare @intlen int

declare @count int

declare @indexb int

declare @indexe int

set @intlen=len(@code)

set @count=0

set @indexb=1

if @no=0

if charindex(@code,@str,@indexb)<>0

return left(@str,charindex(@code,@str,@indexb)-1)

else

return @str

while charindex(@code,@str,@indexb)<>0

begin

set @count=@count+1

if @count=@no

break

set @indexb=@intlen+charindex(@code,@str,@indexb)

endif @count=@no

begin

set @indexe=@intlen+charindex(@code,@str,@indexb)

if charindex(@code,@str,@indexe)<>0

return substring(@str,charindex(@code,@str,@indexb)+len(@code),charindex(@code,@str,@indexe)-charindex(@code,@str,@indexb)-len(@code))

else

return right(@str,len(@str)-charindex(@code,@str,@indexb)-len(@code)+1)

endreturn ''end

2樓:

可以使用as關鍵字

select

'a' as 欄位1,

'b' as 欄位2 ,

'c' as 欄位3

..from t

3樓:匿名使用者

sql 2005 可以試試這個,一句sql搞定declare @str varchar(1000)declare @x xml

set @str='a,b,c,d'

select id

from (select [value] = convert(xml , '' + replace(@str , ',' , '

4樓:

以“,”號分隔的話,這個你可能需要用函式或儲存過程來實現。用普通的sql語句是不好實現的

5樓:匿名使用者

syht2000 正解

6樓:匿名使用者

就是用sql 沒用到jdbc 或 hibernate 嗎?

sql資料庫如何從兩張不同的表中,篩選出不同的欄位,如a表中選a,b兩個欄位,b表中選c,d欄位,求sql語句

7樓:匿名使用者

若有相關聯的欄位的話,用內連線

select a,b,c,d from 表 inner join 另外一張表 on 條件 = 條件

8樓:胤漱璺

select a,b,c,d from a表,b表 where 表a和表b關聯欄位;

9樓:

有關聯欄位:

select a,b,c,d from 表 inner join 另外一張表版 on 條件權 = 條件

沒有關聯欄位:

select a,b from 表

union all

select c,d from 另外一張表

10樓:匿名使用者

select a.c,a.d,b.a,b.b,b.gfrom a,b

where a.a = b.a(+)

and a.b = b.b(+)或者來

select a.c,a.d,b.a,b.b,b.gfrom a,b

where a.a (+)= b.a

and a.b (+)= b.b加號源

位置要看哪個為主表

我要寫一個sql查詢語句,select * from table where id in ('a','b','c','d');

11樓:匿名使用者

declare @

權val varchar(100)=''

declare @sql varchar(max)set @val='''a'''+','+'''b'''+','+'''c'''+','+'''d'''

set @sql='select * from tb where id in ('+@val+')'

print @sql

exec (@sql)

12樓:丘位元灬憶殤

string sql = "select * from table where id in ()";

string ids = "";

foreach(var item in list)ids = ids.substring(1);

sql = string.formart(sql,ids);

mysql中如何取一個表中某個欄位最後的值! 如,取a表b欄位中c字元對應的id

13樓:匿名使用者

select id from a where b like '%c%'

14樓:匿名使用者

select top 1 id from a order by desc b

高分求助,sql注入,高手請進

sql注入就是利用抄sql的語言特徵來使sql條件無bai效而已。舉個du例子 你登入檢驗的 zhisql 是 select form user db where id 你輸入的id and pas 你輸入的密碼 你知道一 dao個人的id但是不知道他的密碼,可是你很想用他的密碼來登入,怎麼辦呢?你...

問這個SQL語句該怎樣寫,sql語句應該怎樣寫?

delete from table where a not in 刪除主鍵不在其中的多餘資料 select min a from table group by b,c 按照b,c分組查詢出最小的主鍵 不確定你的資料庫,以及版本是什麼.你可以用 olap 函式 row number 撇開主鍵 a 這是...

SQL語句中Sql是什麼意思,SQL語句中AS是什麼意思?

是且的意思,這句話的意思是 從article表中選擇所有列,這些列滿足type id為data type sql的值。data type sql是乙個表示式。不過。感覺怪怪的。你用的是oracle的sql 語句set define sql select from empwhere empno emp...