你从城市人员表里面选出男性,60岁以上的人。我:select * from country_population where sex=1 and age>60还有写法吗?
汗……我只会这种
憋曲了半天
select * from country_population where sex=1 and id in
(select id from country_population where age>60)我要的是比第一种效率高,比第二种简单的
更汗……
我:“是不是一张表??”
“对,就一张表”
是不是主键只有id?
对,只有id我考……真的不会了,还有什么写法啊?
汗……我只会这种
憋曲了半天
select * from country_population where sex=1 and id in
(select id from country_population where age>60)我要的是比第一种效率高,比第二种简单的
更汗……
我:“是不是一张表??”
“对,就一张表”
是不是主键只有id?
对,只有id我考……真的不会了,还有什么写法啊?
解决方案 »
- vb怎么样让前一实例捕获这个消息 并做出处理?
- 公共模块问题
- 如何让MSN图标隐藏呀?
- 如何将access中ole中的excel表格放到word中?急!!!
- 怎样判断计算机是否正在运行某个软件?(在线等待!)
- 用Vb本身提供的功能设计报表(不借助于任何第三方控件)
- WebBrowser 控件的 WebBrowser1.document.designMode='On'
- 谁能告诉我如何在textbox中的任一位置加载图片。
- 关于vb的问题
- 怎样打印mschart所绘制的图表?急
- 初学者,关于窗体间传值和如何实现带星号的模糊查询,请高手救急
- 用vb代码把access中的数据导入到excel中,字体可不可以加删除线
这样写效率高,因为sql语句中where 条件是从右到左进行的,当然要把最多的记录先去掉了,这样快点呵呵,只能这么理解了!!!
条件的位置也可以快么?以前一直不知道。
我认为select 字段1,字段2的不正确
如果他给我具体要查哪些记录,我会这样写,没有给具体,只能这样了
一般来说 60岁以上是会少一点
但是他问的是有么有更简单的写法,我说第一种简单,但是他又说不行
怪异了
不过我同意把age>60调换过来
只是这样写不是简单啊,是效率问题啊,是不是我没有听懂……
总之被鄙视
select 姓名 from country_population where sex=1 and age>60
sex=1 and age>60和age>60 and sex=1是一样的.
引用你的贴子 “如果sex=0表示女性的话查询条件可以写成where sex*age>60”
------------------------------------------------------------------------------
运行的快慢与索引的优化有很大的关系。
if (列sex与age已单独建立索引)
where sex=1 and age>60 较快
else
where sex*age>60 较快
end if
THANK YOU
select * from country_population where sex=1
union
select * from country_population where age>60还有一种:
select * from country_population with(index(索引)) where sex=1 and age>60别忘了给帖子加分哦~~!!!
union
select * from country_population where age>60这种组合语句所得的结果与 select * from country_population where sex=1 and age>60 是不同的。
select * from country_population where sex=1
union
select * from country_population where age>60帅哥,这样写肯定是不对的
你写一个出来,记录肯定多n倍莫依,你可以说说你是怎么写的吗?(就是那个工程师告诉你题目的时候^_^)
如果是or就可以。
比如: select * from country_population where sex=1 or age>60