avatar
请教一个query# Database - 数据库
c*y
1
有一个大table把数据都浑在一起了, 结构酱紫:
BookId DataName DataValue
1 Title t1
1 Author a1
1 Publisher p1
2 Title t2
2 Author a2
2 Publisher p2
3 Author a3
3 Publisher p3
如何把所有没有Title的BookId选出来, 不是选Title值为空的, 而是根本就没有这一行的
//bow
avatar
s*e
2
(select distinct bookid from table) except
(select distinct bookid from table where dataname = 'title' )

【在 c***y 的大作中提到】
: 有一个大table把数据都浑在一起了, 结构酱紫:
: BookId DataName DataValue
: 1 Title t1
: 1 Author a1
: 1 Publisher p1
: 2 Title t2
: 2 Author a2
: 2 Publisher p2
: 3 Author a3
: 3 Publisher p3

avatar
c*y
3
thanks!
hmm.. seems mysql doesn't support EXCEPT, doesn't support nested queries
neither

【在 s***e 的大作中提到】
: (select distinct bookid from table) except
: (select distinct bookid from table where dataname = 'title' )

avatar
s*e
4
I know nothing about mysql. hehe.
Just checked its documents, it seems mysql supports subqueries now.
If so, you could write in this way:
select distinct bookid from table where
bookid not in ( select distinct bookid from table where dataname = 'title')

【在 c***y 的大作中提到】
: thanks!
: hmm.. seems mysql doesn't support EXCEPT, doesn't support nested queries
: neither

avatar
c*y
5
thanks
it supports nested queries from 4.0, i'm using 3.21 :(
i figured it out by store the output from sub-query into an array

【在 s***e 的大作中提到】
: I know nothing about mysql. hehe.
: Just checked its documents, it seems mysql supports subqueries now.
: If so, you could write in this way:
: select distinct bookid from table where
: bookid not in ( select distinct bookid from table where dataname = 'title')

avatar
r*y
6
use NOT EXISTS

【在 c***y 的大作中提到】
: thanks!
: hmm.. seems mysql doesn't support EXCEPT, doesn't support nested queries
: neither

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。