select * from userinfo where userinfo.userid = (select distinct news.userid from news where news.parentclassid =1)按你的要求,SQL语句看不出哪个地方可以提高效率或简化了.
解决方案 »
- 个性下拉菜单效果
- 表单无法提交
- FreeTextBox1.6.3中文版错误???谢谢(就剩10分了)
- 大虾,,帮忙啊,一下午了.button事件怎样取得gridview模板列中panel控件中的textbox的值.急啊....................
- 把数据库里的一条记录绑定到了TextBox上,为何再次修改,修改不了
- aspnetpager绑定的问题
- 开发自助建站系统需要哪几个模块
- 我是初学者想问个问题?
- 求救,执行.exe文件
- 谁有 vs.net 下载的请给个链接 : [email protected]
- DropDownList 绑定GridView
- 通过第一个网页的主题(Title),在第二个网页上出现这个主题的 文章怎样实现呀
IF EXISTS(SELECT * FROM sysobjects WHERE name='存储过程名')
DROP PROCEDURE 存储过程名
GOcreate procedure 存储过程名
@parentclassid int
as
select * from userinfo where userinfo.userid = (select distinct news.userid from news where news.parentclassid =@parentclassid )
go存储过程名 1理论上来说,用存储过程的效率怎么也比直接的SQL高那么一点点。。
有一个用户表userinfo
userid(用户id) username(用户名称) 联系信息。还有一个应用表zhaopinid(自动编号)userid(对应userinfo表的用户id) ProvinceId(省份)CityId(城市)在程序中,工作城市是可以多选的,现在要求,当别人查询省份的所有招聘求职的时候,显示userid username ProvinceId
显示这些内容,用户名不能重复
select distinct z.userid,u.username,z.ProvinceId from zhaopin as z
left join userinfo as u
on z.userid=u.userid
where ProvinceId='要查询的省份'
因为涉及2各表,所以运用到集运算(join),效率肯定比从单个表中读取数据要低,但一般应用足够了,除非你的数据表记录极多。
还有一种不使用集运算的办法:
select userid,uername,'要查询的省份' as ProvinceId from userinfo
where userid in (select distinct userid from zhaopin where ProvinceId='要查询的省份')如果一味追求高效的话设计到一个表肯定会高一些,不过会产生大量冗余。
select uid.userid,userName,parentclassid from userinfo join
(select userid,parentclassid from news where parentclassid=1 group by userid,parentclassid )uid
on userinfo.userid=uid.userid
从news表查出符合记录的userid,然后再跟userinfo关联
不要去用in
然后再对SQL语句进行优化