how to show 2 value and one values count from 3 table using mysql

时间:2017-08-05 10:48:14

标签: mysql

I have 3 tables

Table1 (theoryquestion)

id | question | mark | technology 

Table2 (mark)

 mark | id 

Table3 (technologies)

technology | id

I want to select count of question from corresponding mark and tech,

I have tried this

SELECT m.mark_name
     , t.techname
     , COUNT(q.question) 
  FROM question_mark m
  JOIN theoryquestion q
    on q.mark = m.mark_name 
   and q.technology = t.techname 
  JOIN technologies

2 个答案:

答案 0 :(得分:0)

You should use a proper on clause for join the table technologies and use group by for trigger the aggregation function (count)

SELECT 
    question_mark.mark_name
    ,technologies.techname
    ,COUNT(theoryquestion.question) 
FROM question_mark 
INNER JOIN theoryquestion on theoryquestion.mark=question_mark.mark_name 
INNER JOIN technologies theoryquestion.technology=technologies.techname 
GROUP BY  question_mark.mark_name ,technologies.techname

答案 1 :(得分:-2)

this worked for me.......... thank zzz

SELECT question_mark.mark_name,technologies.techname,COUNT(theoryquestion.question) FROM theoryquestion INNER JOIN question_mark on theoryquestion.mark=question_mark.mark_name INNER JOIN technologies on theoryquestion.technology=technologies.techname GROUP BY question_mark.mark_name ,technologies.techname