2014-07-06 41 views
1

我有一個關於反饋系統的寵物項目,其中一個表達顧客的問題,另一個表示服務檯的回答者。MySql操作員的複雜性


//////////////////////////////////////////////////////////////////////// 
Customers_Question table   AND helpdesk_answers includes: 
Qst_id(pk),       Qst_id(pk)(FK) 
qst_title,        helpdesk_answer 
qst_comment, 
qst_customer_name, 
qst_date 

得到答案MySQL查詢是:

SELECT*from customers_question, helpdesk_answers 
WHERE customers_qst.Qst_id = helpdesk_answers(FK Qst_id) 

我得到的所有問題,這已經回答了。 問題:我如何獲得或計算未答覆的問題?

回答

0

使用IS NULL - >

SELECT cq.* FROM customers_question cq 
LEFT JOIN helpdesk_answers ha 
    ON cq.Qst_id = ha.Qst_id 
WHERE ha.Qst_id IS NULL 

OR

使用NOT IN() - >

SELECT * FROM customers_question 
WHERE Qst_id NOT IN 
    (SELECT DISTINCT Qst_id FROM helpdesk_answers) 
+0

每個人都在這裏是如此的驚人,你都是極客......作品像魅力 – PULabs

+0

很高興我們可以提供幫助。確保標記答案,因爲它會從未答覆的列表中刪除您的問題。 – Sean

0

你可以使用其他答案中給出的代碼來獲得問題。

爲了統計返回的行數,您可以看到this answer