作者anvil (夏天的风)
看板Database
标题Re: [SQL ] 请问如何在有多个主键情况下找下一笔( …
时间Tue Sep 26 11:30:42 2006
※ 引述《PsMonkey (痞子军团团长)》之铭言:
: ※ 引述《anvil (夏天的风)》之铭言:
: : 糟糕 造成误会了,抱歉。我更正一下。
: : A B
: : --------------------------------
: : 1 1
: : 3 2
: : 2 1
: : 1 2
: : 3 5
: : --------------------------------
: : 以上是资料内容
: : 我想要找 (1,2) 的下一笔,也就是 (2,1)
: : 或是给定 (A,B)=(3,4) ,找出不小於(3,4)的资料,
: : 也就是 (3,5)
: : 请问mySQL指令要怎麽下呢?谢谢:)
我想要做的动作类似lexicographic searching
我目前的作法是这样:
select * from table where (`A`=3 and `B`>4) or (`A`>3)
order by `A` asc,`B` asc limit 1
但是假如我想比对的是更多的栏位,除了硬干条件式以外,
像这样:
select * from table where (`A`=Va and `B`=Vb and ... and `Y`=Vy and `Z`>Vz ) or
(`A`=Va and `B`=Vb and ... and `Y`>Vy ) or
.................................
.................................
(`A`=Va and `B`>Vb ) or
(`A`>Va )
order by `A` asc,`B` asc ,......,`Z` asc
实在想不出别的作法。不知各位高手有什麽看法?
--
Cast a cold eye
On life, on death.
Horseman, pass by!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 125.232.195.80
※ 编辑: anvil 来自: 125.232.195.80 (09/26 11:49)
※ 编辑: anvil 来自: 125.232.195.80 (09/26 11:49)
※ 编辑: anvil 来自: 125.232.195.80 (09/26 11:49)