當前位置:首頁 » 編程語言 » 根據sql語句查id
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

根據sql語句查id

發布時間: 2023-03-07 02:33:20

❶ asp sql 查詢id為1或2或3的值 sql語句怎麼寫

用or查詢不走索引,效果不理想,建議用in, 如果該查詢欄位建了索引,in會極大的提高查詢速度

select * from Table where xx in ('1','2','3');

你也可以考慮把參數放到1個數組中,循環生成sql中條件的部分

❷ java中sql語句根據項目id查詢id下所有屬性欄位

你這個方法寫的好奇怪,你傳入一個參數,再返回它有什麼意義呢,你用的是hibernate,hibernateDao.executeSqlQuery(sql)應該用個對象接收下吧,你這樣寫出來沒什麼意義這個方法

❸ 用SQL語句搜索ID,返回姓名,寫公共類

public string IDtoName(string ID)
{
SqlConnection con=this.getcon();
string sql="select name from table where id='"+ID+"'";
SqlDataAdapter sqlada=new SqlDataAdapter(sql,con);
DataSet myset=new DataSet();
sqlada.Fill(myset);
string name=myset.Table[0].Rows[0][0].ToString();
return name;
}
Label1.Text=IDtoName(ID);//自己輸入的一個ID號就可以獲取到名字,希望這是你想要的答案,但是個人建議是return 一個dataset ,然後再在dataset里獲取想要的值

❹ SQL怎麼用ID字元串查詢ID

1、新建表drop table if exists Category; create table Category ( cateId int(5) not null AUTO_INCREMENT, chiName varchar(80), primary key (cateId) ); drop table if exists OpenRecord; create table OpenRecord ( opreId int(5) not null AUTO_INCREMENT, cateIds varchar(80), primary key (opreId) );

2、初始化數據
insert Category(chiName) values (fish),(shrimp),(crab),(tiger); insert OpenRecord(cateIds) values(1,2); insert OpenRecord(cateIds) values(2,3);

3、查詢OpenRecord中Id為1包括的Category 。
#錯誤的方法
select * from Category where (select INSTR(cateIds,cateId) from OpenRecord where opreId=1)

#正確的方法
select * from Category where (select FIND_IN_SET(cateId,cateIds) from OpenRecord where opreId=1)

用INSTR會出現當ID大於10的時候,查ID為1的數據,會把1,10,11,12......的都拿出來 。
4、擴展會出現的問題 。
用FIND_IN_SET可以解決ID是用","號隔開的問題 。然而會有另外的兩種情況 。
A、當ID不包含",",但是用別的符號分開時,如用"|" 。我們有如下的解決辦法
select *
from Category
where (select FIND_IN_SET(cateId,REPLACE(cateIds,|,,)) from OpenRecord where opreId=1)

❺ sql語句如何獲取當前ID,求解~

假如你通過URL參數或表單提交的參數名為id,那麼可以這樣:
<%
Dim Rs,Sql
Set
Rs = Server.CreateObject("ADODB.RecordSet")
Sql = "SELECT * FROM Music_mv WHERE Id = " & CLng(Request("id"))
Rs.Open Sql,Conn,1,1
%>
如果還有問題歡迎追問,問題解決請及時選為滿意回答,謝謝.

❻ 用sql語句查詢ID號距當前ID號最近的且滿足相關條件的數據

select col_a,id
from (
select col_A,id,row_number() over (partition by col_A order by ABS(id-12345)) as rn
from table
where id<>12345 and col_A='a'
)
where rn=1

❼ SQL 語句 根據最小值查詢用戶id

select userID from user a left outer join(select min(checkper) as checkper,role_id,dept_id from role group by dept_id,role_id) b on a.role_id=b.rold_id and a.dept_id=b.deptid

❽ 求 sql語句 查詢出來一張表中的id欄位長度是11位的id id的字元類型是 varchar 在此謝過過為了

select [id] from tablename where len([id])=11
註:id屬於sql關鍵字,若當作自己表中的欄位名,查詢時應用中括弧括起來