MYSQL查询问题:选择所有线程,按线程对应的号数排序
我的标题可能有点令人困惑,所以这是我的问题。
这是我的表:
CREATE TABLE `b_posts` (
`thread` int(12) NOT NULL,
`no` int(12) NOT NULL,
`comment` text NOT NULL,
`gone` int(1) NOT NULL default '0',
PRIMARY KEY (`no`),
FULLTEXT KEY `comment` (`comment`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
我现在需要一个查询,选择所有未消失的线程(意味着消失为 0,如果完成为 1,则意味着该线程已被删除)。选择线程的顺序应该根据与原始线程具有相同线程的否的数量。
进一步说明:
thread | no | comment | gone
100 | 100 | hello there, this is the thread! | 0
100 | 102 | this is a reply in the thread 100 | 0
100 | 103 | another reply in the same thread | 0
104 | 104 | this is a different thread | 0
104 | 105 | a reply to the different thread | 0
我现在想通过查询按以下顺序获取以下数据:(
thread | no | comment | gone
100 | 100 | hello there, this is the thread! | 0
104 | 104 | this is a different thread | 0
线程启动器是在线程 == no 时定义的)
My title probably is a bit confusing, so here is my problem.
This is my table:
CREATE TABLE `b_posts` (
`thread` int(12) NOT NULL,
`no` int(12) NOT NULL,
`comment` text NOT NULL,
`gone` int(1) NOT NULL default '0',
PRIMARY KEY (`no`),
FULLTEXT KEY `comment` (`comment`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
I now need a query which selects ALL threads which are not gone (means gone is 0, if done is 1 this would mean the thread has been deleted). The order of which the threads are selected should be by the amount of no's who have the same thread like the original.
Further explanation:
thread | no | comment | gone
100 | 100 | hello there, this is the thread! | 0
100 | 102 | this is a reply in the thread 100 | 0
100 | 103 | another reply in the same thread | 0
104 | 104 | this is a different thread | 0
104 | 105 | a reply to the different thread | 0
I now want to get the following data in the following order with my query:
thread | no | comment | gone
100 | 100 | hello there, this is the thread! | 0
104 | 104 | this is a different thread | 0
(Thread starter is defined when thread == no)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的限定符“thread = no”和“gone = 0”,我认为将它们包含在结果列中没有意义......但是,我确实包含了每个线程总条目的子计数
Since your qualifier of "thread = no" and "gone = 0", I saw no point in including them in the result columns... however, I did include the sub-count of total entries per thread