当前位置:首页 » 编程语言 » 根据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关键字,若当作自己表中的字段名,查询时应用中括号括起来