1. sql 獲取某一行某一列的值
SQL裡面只有列才是條件 如果你表裡面有主鍵(比如說ID)的話那就好找
select 列名 from table_name where ID=?
就可以確定了
2. sql 選取某列某行的值
就算不是 union all 結果集,SQL語句也無法直接實現你要的效果。
只有做存儲過程,聲明變數,分別保存第一行和第二行的數據,進行運算,輸出結果。
3. 資料庫讀取數據如何讀取指定特定的幾行
select * from [table] where id between 3 and 8
這樣取的是3-8之間的行數據
4. SQL 如何取出每一行欄位的值不同的行
先列轉行在查詢
select* from tablea_3
NO A B C D E F G
a 1 0 0 0 1 0 0
c 0 0 0 0 0 0 0
b 3 2 0 0 1 3 2
declare @s varchar(8000)------------------------------------------先列轉行
set @s = 'create table tablea_32 (no varchar(20)'
select @s = @s + ',' + no + ' varchar(10)' from tablea_3
set @s = @s + ')'
exec(@s)
print @s
--藉助中間表實現行列轉換
declare @name varchar(20)
declare t_cursor cursor for
select name from syscolumns
where id=object_id('tablea_3') and colid > 1 order by colid
open t_cursor
fetch next from t_cursor into @name
while @@fetch_status = 0
begin
exec('select ' + @name + ' as t into tablea_33 from tablea_3')
set @s='insert into tablea_32 select ''' + @name + ''''
select @s = @s + ',''' + rtrim(t) + '''' from tablea_33
exec(@s)
exec('drop table tablea_33')
fetch next from t_cursor into @name
end
close t_cursor
deallocate t_cursor
--查看行列互換處理結果
select * from tablea_32
declare @a int
declare @b int
declare @c char(10)
select @a= min( ascii(no)) from tablea_32
select @b= max( ascii(no)) from tablea_32
while (@a<=@b)
begin
set @c=char(@a)
insert into #A
select distinct a,no
from tablea_32 where no=@c and a<>0
insert into #B
select distinct B,no
from tablea_32 where no=@c and B<>0
insert into #C
select distinct C,no
from tablea_32 where no=@c and C<>0
set @a=@a+1
end
if exists ( select count(distinct A) from #a having count(distinct a)>1)
PRINT 'A'
if exists ( select count(distinct B) from #B having count(distinct B )>1)
print 'B'
if exists ( select count(distinct C) from #C having count(distinct C )>1)
print 'C'
5. SQL Server如何取得某一列中的某一行數據
SQL Server如何取得某一列中的某一行數據?
按你的意思查詢出來的只是一個值,列與行的交叉只有一個數據.
SELECT [列名] FROM [表名] WHERE [列名]=值
如果要顯示某列數值
SELECT [列名] FROM [表名]
如果顯示某列值為定值時的一行
SELECT * FROM [表名] WHERE [列名]=已知值
6. 【SQL語句】如何從查詢的結果中獲取指定行
如果你是MySQL的話:select x1,y1 from tb_Load where x2=22 and y2=77 limit 3,1
7. sql server資料庫如何抽取指定行列的數據
with t as(
select * ,row_number() over(order by getdate()) as bz
from tablename )
select * from t where bz=..
你想要第幾row,就讓bz 等於幾了。
一般不會有人問第幾column,直接看下錶,你選取那個欄位就好了
8. sql server如何抽取指定行列的數據,最好寫出抽取的語句
with t as(
select * ,row_number() over(order by getdate()) as num
from tablename )
select * from t where num=3
上述例子,num=3就是指取第三條,要抽取其他行,手工調整此數即可,其實SQL Server沒有指定行號、列號的取數方法,給的例子是按記錄插入表的順序抽取
9. sql2008怎樣獲取指定行的數據謝謝
方法1:
SELECT * FROM 表 WHERE id >= 8 AND id <= 15
方法2:
SELECT TOP 8 * FROM 表 ORDER BY id DESC
10. SQL中如何獲取滿足某一條件的行中的某個值
declare @st char(255)
select @st=C from tb where A=20