簡體   English   中英

新手試圖解決MySQL查詢邏輯問題

[英]Newbie trying to solve a MySQL query logic issue

我將盡可能簡單地解釋這一點。 任何幫助將不勝感激,因為我不是很擅長設計查詢。

我有3個表:(我已經在這個問題的用戶表中刪除了不必要的列)

USERS:
id,    username,    password

PENDINGREVIEW:
id,    articleid,    requestid,    content,    writerid,    datewritten

ARTICLES:
id,    title,    length,    requestedby,    content,    writtenby,    daterequested,    datecompleted

所以說我有review.php review.php我希望它顯示特定用戶的pendingreview表中的所有文章。 所以像這樣:

SELECT * FROM pendingreview WHERE requestid = $userid (where $userid = the id of the user)

我實際上想要在review.php上顯示的是articles表中的articles列表以及pendingreview表中與每篇文章相對應的文章數量。 該列表必須僅由用戶請求的文章組成。

所以我想將review.php看起來像這樣:

  • Your "How to build a bike" article request has 3 articles pending review.
  • Your "How to mow the lawn" article request has 12 articles pending review.

任何有關如何做到這一點的幫助將不勝感激!

SELECT  a.title, COUNT(*) TotalPending
FROM    Articles a
        INNER JOIN PendingReview b  
            ON a.ID = b.articleID
WHERE   b.RequestID = 'ID HERE'
GROUP   BY a.title

要進一步了解聯接,請訪問以下鏈接:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM