2016-02-24 31 views
1

我正在努力如何實現這個表。 我想其他批次的記錄,以另一列就像在下面的圖片PHP | MYSQL:2個或更多列的單個人

enter image description here

這是我的查詢:

SELECT 
      stud_name, 
      equivalent 
    FROM tb_student_record 
    WHERE instructor_id = 'INST-20131296' 
      AND criteria = 'Quiz' 
      AND description = 'BIOETHICS' 
      AND subj_code = 'N049' 
      AND term = 'Midterm'; 

任何建議將不勝感激。

+0

尋找關鍵點 – sagi

+0

你想做什麼?合併它們(等同)? –

+0

請詳細一點,人們需要清楚嗎? –

回答

1

更新查詢:

SELECT 
    stud_name, 
    GROUP_CONCAT(equivalent SEPARATOR '#') as equivalent 
FROM tb_student_record 
WHERE instructor_id = 'INST-20131296' 
    AND criteria = 'Quiz' 
    AND description = 'BIOETHICS' 
    AND subj_code = 'N049' 
    AND term = 'Midterm' 
GROUP BY `stud_name`; 

得到的結果在PHP中使用explode功能分開。 功能會像:

$當量=爆炸( 「#」,$ yourFetchArr->同等學歷;)//取決於 你取的,我用mysql_fetch_object();

現在$equivalent[0]$equivalent[1]是兩個單獨的等價物;

+1

進出口的想法,謝謝先生:) – CallMeJeo

+0

@CallMeJeo,如果答案是有用的然後標記爲答案。 –

-2

你可以做一個子查詢應該是這個樣子

SELECT 
      stud_name, 
      equivalent, 
      (SELECT 
       equivalent 
       FROM tb_student_record 
       WHERE instructor_id = 'INST-20131296' 
       AND criteria = 'Quiz' 
       AND description = 'BIOETHICS' 
       AND subj_code = 'N049' 
       AND term = 'Midterm';) AS equivalent2 
    FROM tb_student_record 
    WHERE instructor_id = 'INST-20131296' 
      AND criteria = 'Quiz' 
      AND description = 'BIOETHICS' 
      AND subj_code = 'N049' 
      AND term = 'Midterm'; 

然後,只需改變內部查詢,選擇查詢的詳細信息。如果你給我更多的細節,我可以更新我的代碼,以更正確地反映傳播者查詢

相關問題