主题:求助SQL查询问题
piaoyexie
[专家分:1380] 发布于 2006-10-29 23:17:00
环境 SQL 2000
所用数据库:pubs
涉及表:authors,publishers
查询内容:查询没有出版社的州名和该州的所有作者名。
use pubs
go
select state,au_lname,au_fname
from authors
where state not in
(
select state from authors
)
go
为什么上面的查询方法查不出来?
应该如何查询才正确?
回复列表 (共15个回复)
沙发
lionStone [专家分:0] 发布于 2006-10-30 10:08:00
查询没有出版社的州名和该州的所有作者名 ?
这语句有点怪~~~~~~~~~~~
板凳
chengli520hy [专家分:870] 发布于 2006-10-30 10:57:00
use pubs
go
select state,au_lname,au_fname
from authors
where state in
(select state from authors where not authors.state in (select state from stores))
group by state,au_lname,au_fname
go
3 楼
piaoyexie [专家分:1380] 发布于 2006-10-30 12:29:00
[quote]查询没有出版社的州名和该州的所有作者名 ?
这语句有点怪~~~~~~~~~~~[/quote]
语句是怪
意思应该明确吧?
就是查询作者所在的州名及作者名,且作者所在州没有出版社
4 楼
piaoyexie [专家分:1380] 发布于 2006-10-30 12:30:00
[quote]use pubs
go
select state,au_lname,au_fname
from authors
where state in
(select state from authors where not authors.state in (select state from stores))
group by state,au_lname,au_fname
go
[/quote]
不是查询 stores 表里的 state 啊
而是 publishers 表里的啊
5 楼
wdkshp [专家分:5490] 发布于 2006-11-02 14:57:00
select state,au_lname,au_fname from authors where state not in (
select state from authors )
改成
select authors.state,authors.au_lname,authors.au_fname from authors where authors.state not in (select publishers.state from publishers)
试一试
我是这么猜想的
表autoors里有字段state(作者所在州)、au_lame)、au_fname(有一个可能是作者姓名)
表publishers里有字段state(出版社所在州)
6 楼
piaoyexie [专家分:1380] 发布于 2006-11-02 21:55:00
[quote]select state,au_lname,au_fname from authors where state not in (
select state from authors )
改成
select authors.state,authors.au_lname,authors.au_fname from authors where authors.state not in (select publishers.state from publishers)
试一试
我是这么猜想的
表autoors里有字段state(作者所在州)、au_lame)、au_fname(有一个可能是作者姓名)
表publishers里有字段state(出版社所在州)[/quote]
没用
两个返回结果都是一样的:空
而从两个表的内容看不可能为空
7 楼
Leo64823900 [专家分:960] 发布于 2006-11-03 23:10:00
use pubs
go
select state,au_lname,au_fname
from authors
where state not in
(
select distict state from publishers
)
go
8 楼
piaoyexie [专家分:1380] 发布于 2006-11-04 17:44:00
[quote]use pubs
go
select state,au_lname,au_fname
from authors
where state not in
(
select distict state from publishers
)
go
[/quote]
distict 是什么东东呀?
无效喔
9 楼
Leo64823900 [专家分:960] 发布于 2006-11-05 12:11:00
Hi
Key in mistake. It should be DISTINCT
[url=http://www.programfan.com/club/editbbs.asp?id=625599&action=editreply]Regards[/url]
10 楼
piaoyexie [专家分:1380] 发布于 2006-11-05 18:35:00
[quote]Hi
Key in mistake. It should be DISTINCT
[url=http://www.programfan.com/club/editbbs.asp?id=625599&action=editreply]Regards[/url][/quote]
use pubs
go
select state,au_lname,au_fname
from authors
where state not in
(
select DISTINCT state from publishers
)
go
返回结果还是空。。。
我来回复