易截截图软件、单文件、免安装、纯绿色、仅160KB

sql 问题 - Oracle / 开发

Select * from UserInfo where uif_UserCode in (1,12) 
用in在数据量大的时候效率不高,(1和12是传过来的值)除了这种方法还可以怎么写,
有人说用exists 到底要怎么写呢 ?
列表值不多,用in性能也啥大不了的
其实列表项不多,in 和exists差别很小
如果要用exists必须存在另一个表中,uif_UserCode上建立索引。
Select * from UserInfo a where exists( select 1 from tempUserInfo b where a.uif_UserCode =b.uif_UserCode )

引用
Select * from UserInfo where uif_UserCode in (1,12)
用in在数据量大的时候效率不高,(1和12是传过来的值)除了这种方法还可以怎么写,
有人说用exists 到底要怎么写呢 ?


in 的话只要范围不大跟exists关键字差不多 

要是范围大的话 可以考虑exists,可以建索引吧
Select * from UserInfo a where exists(select 1 from UserInfo where a.UserCode=UserCode)

Select * from UserInfo where uif_UserCode in (1,12) 

改成
Select * from UserInfo where uif_UserCode=1 or uif_UserCode=12

忘记哪个效率高了,呵呵,你试试

引用

Select * from UserInfo where uif_UserCode in (1,12)

改成
Select * from UserInfo where uif_UserCode=1 or uif_UserCode=12

忘记哪个效率高了,呵呵,你试试


传的1和12不是固定的,有可能还会是3个数或者更多呢?

如果不用exists还有什么更好的方法吗?

Select * from UserInfo where uif_UserCode=1 or uif_UserCode=12


相关问答:

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

[原创] ORACLE 连接字串 - Oracle / 非技术区

假设table01 中有 以下资料
emp_no emp_name
------- ------------
0001 TOM
0002 JOHN
0003 MARY
常用电话 
而我们要得到以下的OUTPUT (或是各种其他的output)
0001,TOM
0002,JOHN ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

求一个SQL语句 - MS-SQL Server / 基础类

字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号