2

私がやりたいのは、類似性/類似性によって質問を並べ替え、Resultテーブルからのポイントに基づいてテーブル から結果を取得することPointです。

: query = 'ドイツの場所'

次のテーブルがあります。

テーブルの質問

+---------+-----------+---------------+---------------------------------+
| ques_id  | question                                                   |
+---------+-----------+---------------+---------------------------------+
|     1    |  Where is Germany located                                  |
+---------+-----------+---------------+---------------------------------+
|     2    |  where is Germany located on a map                         |
+---------+-----------+---------------+---------------------------------+
|     3    |  where is Germany located in Europe                        |
+---------+-----------+---------------+---------------------------------+

表の結果

+---------+-----------+---------------+---------------------------------+
| resu_id  | result                                                     |
+---------+-----------+---------------+---------------------------------+
|     1    |  Germany is located in Europe                              |
+---------+-----------+---------------+---------------------------------+
|     2    |  Northern hemisphere in Europe                             |
+---------+-----------+---------------+---------------------------------+
|     3    |  between France & Poland                                   |
+---------+-----------+---------------+---------------------------------+
|     4    |  Germany is located in central Europe                      |
+---------+-----------+---------------+---------------------------------+
|     5    |  South of Denmark                                          |
+---------+-----------+---------------+---------------------------------+
|     6    |  52 degrees North, 13 degrees East                         |
+---------+-----------+---------------+---------------------------------+
|     7    |  located on the continent of Europe                        |
+---------+-----------+---------------+---------------------------------+

テーブルポイント

+---------+-----------+-----------+-----------+
| pont_id |  ques_id  |  resu_id  |  point    |
+---------+-----------+-----------+-----------+
|    1    |     2     |     6     |    10     |
+---------+-----------+-----------+-----------+
|    2    |     1     |     1     |    8      |
+---------+-----------+-----------+-----------+
|    3    |     2     |     7     |    7      |
+---------+-----------+-----------+-----------+
|    4    |     3     |     5     |    9      |
+---------+-----------+-----------+-----------+
|    5    |     3     |     4     |    8      |
+---------+-----------+-----------+-----------+
|    6    |     1     |     7     |    10     |
+---------+-----------+-----------+-----------+
|    7    |     3     |     2     |    6      |
+---------+-----------+-----------+-----------+
|    8    |     2     |     3     |    4      |
+---------+-----------+-----------+-----------+

私がしようとしました

SELECT resu_id FROM `Point` WHERE ques_id is (**?**) ORDER BY `point`

期待される結果

+---------+-----------+-----------+--------------------------------------------+
| ques_id |  resu_id  |  point    |    result                                  |
+---------+-----------+-----------+--------------------------------------------+
|    1    |     7     |     10    |    located on the continent of Europe      |
+---------+-----------+-----------+--------------------------------------------+
|    1    |     1     |     8     |    Germany is located in Europe            |
+---------+-----------+-----------+--------------------------------------------+
|    2    |     6     |     10    |    52 degrees North, 13 degrees East       |
+---------+-----------+-----------+--------------------------------------------+
|    2    |     7     |     7     |    located on the continent of Europe      |
+---------+-----------+-----------+--------------------------------------------+
|    2    |     3     |     4     |    between France & Poland                 |
+---------+-----------+-----------+--------------------------------------------+
|    3    |     5     |     9     |    South of Denmark                        |
+---------+-----------+-----------+--------------------------------------------+
|    3    |     4     |     8     |    Germany is located in central Europe    |
+---------+-----------+-----------+--------------------------------------------+
|    3    |     2     |     6     |    Northern hemisphere in Europe           |
+---------+-----------+-----------+--------------------------------------------+

質問を関連性でソートし、ポイント値に基づいてそれぞれの結果を表示します。

助けてくれてありがとう、私に厳しくしないでください:)

4

2 に答える 2

1

関連する結果データを探している場合は、次のクエリを試すことができます。

select 
   p.ques_id, p.resu_id, p.point,
--   q.question,
   r.result -- , p.pont_id
from
   result r
   inner join point p on ( r.resu_id=p.resu_id )
--   inner join question q on ( q.ques_id=p.ques_id and q.ques_id=? ) -- // use this if required
   inner join question q on ( q.ques_id=p.ques_id )
order by 
   q.ques_id, p.point desc, r.result desc
;

上記のクエリ実行の出力:

+---------+---------+-------+--------------------------------------+
| ques_id | resu_id | point | result                               |
+---------+---------+-------+--------------------------------------+
|       1 |       7 |    10 | located on the continent of Europe   |
|       1 |       1 |     8 | Germany is located in Europe         |
|       2 |       6 |    10 | 52 degrees North, 13 degrees East    |
|       2 |       7 |     7 | located on the continent of Europe   |
|       2 |       3 |     4 | between France & Poland              |
|       3 |       5 |     9 | South of Denmark                     |
|       3 |       4 |     8 | Germany is located in central Europe |
|       3 |       2 |     6 | Northern hemisphere in Europe        |
+---------+---------+-------+--------------------------------------+
8 rows in set (0.00 sec)

select再度選択したくないフィールドを削除します。

于 2012-06-03T10:56:49.790 に答える
0

私はあなたがこれを望んでいると信じています::

  SELECT result 
  FROM Result 
  inner join Point on (Result.resul_id=Point.resul_id)
  WHERE Point.ques_id = ? ORDER BY Point.point desc limit 1
于 2012-06-02T13:39:13.123 に答える