如何显示发布到我的论坛中的答案数量? [英] How to show the numbers of answers posted into my forum?
问题描述
我正在使用Java技术建立一个论坛.实际上,它几乎快要完成了,但是问题是我想在论坛中显示答案的数量.好吧,让我们深入了解.
i'm making a forum using Java technologies. Actually it is almost near to complete but the problem is I want to show numbers of answer into my forum. Okay let's understand in deeply.
首先,我创建了一个名为index.jsp
的文件,在这里我们可以看到所有问题.对于e.g
,请访问stackoverflow.com,我们在一个问题中也看到了所有问题numbers of answers posted
.这就是我想显示在index.jsp中的全部内容.
Firstly, i've created a file named as index.jsp
where we could see all questions. For e.g
Have a look into stackoverflow.com we see all question as well numbers of answers posted
in one question. That's all i wanted to show into my index.jsp.
我正在使用select * from question_table..
提取所有问题.实际上是进入我的view question
文件.我正在使用在answer's table
中创建的question_id
表来获取答案.您非常清楚要显示答案,特别是我们需要将相同的question_id
保存到答案的表以及问题的表中.
I'm fetching all questions using select * from question_table..
. Actually into my view question
file. I'm fetching the answer using question_id
table which is created into answer's table
. You know very well to show answer in particular we need to save the same question_id
into answer's table as well question's table.
对于e.g:
看看这张桌子,我设计了同样的东西:
look at this table i designed the same thing:
create table if not exists thread_question(
question_id INT NOT NULL auto_increment,
question_title VARCHAR(500) NOT NULL,
question VARCHAR(100000) NOT NULL,
question_dateTime VARCHAR(100) NOT NULL,
PRIMARY KEY(question_id)
);
create table if not exists thread_answer(
answer_id INT NOT NULL auto_increment,
question_id INT NOT NULL references thread_question(question_id),
answer VARCHAR(100000) NOT NULL,
answer_dateTime VARCHAR(100) NOT NULL,
PRIMARY KEY(answer_id)
);
就像您在这里看到的一样,question_id
被保存到两个表中.我在这里使用相同的过程.
As well you could see here, question_id
is saved into two tables. Same process i'm using here.
现在我想在我的主页上显示我的答案数量.任何的想法?在这里可以使用什么.我真的被困在这里.请帮忙!
Now i want to show my number of answers into my main page. Any idea? what can be used here. I really stuck here. Please help!
当然可以,谢谢您的帮助!
Surely, Help would be appreciated!!
已
EDITED:
这是我的完整表格代码:
Here is my full codes of table:
create table if not exists thread_question(
question_id INT NOT NULL auto_increment,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
question_title VARCHAR(500) NOT NULL,
question VARCHAR(100000) NOT NULL,
question_dateTime VARCHAR(100) NOT NULL,
PRIMARY KEY(question_id)
);
create table if not exists thread_answer(
answer_id INT NOT NULL auto_increment,
question_id INT NOT NULL references thread_question(question_id),
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
answer VARCHAR(100000) NOT NULL,
answer_dateTime VARCHAR(100) NOT NULL,
PRIMARY KEY(answer_id)
);
这里是 SCREENSHOT .
请帮助!!
推荐答案
使用内部联接获取每个问题的答案数量
use inner join to fetch number of answer per question
SELECT thread_question.question_id, COALESCE(sub.counts,0) AS NumerOfAnswer
FROM thread_question LEFT JOIN (
SELECT question_id, COUNT(answer_id) AS counts
FROM thread_answer
GROUP BY question_id
) sub ON thread_question.question_id = sub.question_id
ORDER BY NumerOfAnswer
这篇关于如何显示发布到我的论坛中的答案数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!