0

私のテーブル:

tbl_questions =>
qid
question
detail
mcid
cid
uid
answercount
dateposted
status
showname
emailnotify
question_type_id

すべての行を時間ごとにグループ化したいと思います。{dateposted = Ymd H:i:s} {question_type_id を 2} に更新したいのですが、その時間内により多くの行があります。

ええと、誰かが 1 時間に 15 の質問を受け取った場合、タイプ 2 を与えたいと思いますが、その時間内のメッセージ (行) のみです。申し訳ありませんが、私が何を望んでいるかを正確に伝えるのは難しいです。私の英語は下手です。

sample data tbl_questions =>

qid = 1, uid = 1, dateposted = 2013-01-01 10:11:10, question_type_id = 1
qid = 2, uid = 1, dateposted = 2013-01-01 10:16:10, question_type_id = 1
qid = 3, uid = 1, dateposted = 2013-01-01 10:18:10, question_type_id = 1
qid = 4, uid = 1, dateposted = 2013-01-01 10:19:10, question_type_id = 1
qid = 5, uid = 1, dateposted = 2013-01-01 10:20:10, question_type_id = 1
qid = 6, uid = 1, dateposted = 2013-01-01 10:22:10, question_type_id = 1
qid = 7, uid = 1, dateposted = 2013-01-01 10:23:10, question_type_id = 1
qid = 8, uid = 1, dateposted = 2013-01-01 10:24:10, question_type_id = 1
qid = 9, uid = 1, dateposted = 2013-01-01 10:25:10, question_type_id = 1
qid = 10, uid = 1, dateposted = 2013-01-01 10:26:10, question_type_id = 1
qid = 11, uid = 1, dateposted = 2013-01-01 10:27:10, question_type_id = 1
qid = 12, uid = 2, dateposted = 2013-01-01 10:17:10, question_type_id = 1
qid = 13, uid = 2, dateposted = 2013-01-01 10:27:10, question_type_id = 1
qid = 14, uid = 1, dateposted = 2013-01-01 12:27:10, question_type_id = 1

1時間で限界を超えてupdateいるrowsので、そちらにお願いします。posted by uid = 1set question_type_id = 2はそれらの行に入る必要があります。

したがって、期待される出力は次のとおりです。 tbl_questions =>

qid = 1, uid = 1, dateposted = 2013-01-01 10:11:10, question_type_id = 2
qid = 2, uid = 1, dateposted = 2013-01-01 10:16:10, question_type_id = 2
qid = 3, uid = 1, dateposted = 2013-01-01 10:18:10, question_type_id = 2
qid = 4, uid = 1, dateposted = 2013-01-01 10:19:10, question_type_id = 2
qid = 5, uid = 1, dateposted = 2013-01-01 10:20:10, question_type_id = 2
qid = 6, uid = 1, dateposted = 2013-01-01 10:22:10, question_type_id = 2
qid = 7, uid = 1, dateposted = 2013-01-01 10:23:10, question_type_id = 2
qid = 8, uid = 1, dateposted = 2013-01-01 10:24:10, question_type_id = 2
qid = 9, uid = 1, dateposted = 2013-01-01 10:25:10, question_type_id = 2
qid = 10, uid = 1, dateposted = 2013-01-01 10:26:10, question_type_id = 2
qid = 11, uid = 1, dateposted = 2013-01-01 10:27:10, question_type_id = 2
qid = 12, uid = 2, dateposted = 2013-01-01 10:17:10, question_type_id = 1
qid = 13, uid = 2, dateposted = 2013-01-01 10:27:10, question_type_id = 1
qid = 14, uid = 1, dateposted = 2013-01-01 12:27:10, question_type_id = 1
4

1 に答える 1

1

いくつかの手順を進める必要があります。

MySQL を使用していると仮定して、日付と時刻の関数を確認してください。関数HOUR()は、あなたが望むものかもしれません:

SELECT count(id) AS cpt, HOUR(dateposted) AS hour FROM tbl_questions GROUP BY hour ORDER BY cpt DESC;

ここから、最大数と関連する時間 (少なくとも 1 つ、場合によっては複数) を抽出して、テーブル内の関連する行を取得できます。必要な時間の配列を作成し、次のようなクエリを実行できます。

UPDATE tbl_questions SET question_type_id = 2 WHERE HOUR(dateposted) IN (...your list of hours)
于 2013-05-23T16:56:17.663 に答える