由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请教一个query
相关主题
please help with this left join questionask for help with a simple query!!!
有什么优化query的常用方法question on nested query
more HELP: how to make this sql more efficient?请问这两个SQL QUERY有什么错?
A sql questionCan "NOT IN" be expressed in a single block query?
query estimation shows cost 900%?SQL server 2000有hidden records吗?
问一个SQL Querya sql question
再问not exist和not in请问这个query该怎么实现?
如何完成这个sql?[Mysql] how to return NULL count in group by query (转载)
相关话题的讨论汇总
话题: title话题: bookid话题: author话题: publisher话题: query
进入Database版参与讨论
1 (共1页)
c***y
发帖数: 114
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
s***e
发帖数: 284
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

c***y
发帖数: 114
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' )

s***e
发帖数: 284
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

c***y
发帖数: 114
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')

r****y
发帖数: 26819
6
use NOT EXISTS

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

1 (共1页)
进入Database版参与讨论
相关主题
[Mysql] how to return NULL count in group by query (转载)query estimation shows cost 900%?
问个SQL问题问一个SQL Query
MS ACCESS 里面怎么把两个Table combine 到一个table, 而且primary key不重复呢?再问not exist和not in
How to write the query如何完成这个sql?
please help with this left join questionask for help with a simple query!!!
有什么优化query的常用方法question on nested query
more HELP: how to make this sql more efficient?请问这两个SQL QUERY有什么错?
A sql questionCan "NOT IN" be expressed in a single block query?
相关话题的讨论汇总
话题: title话题: bookid话题: author话题: publisher话题: query