SQL文

4177 ワード

book_によるとid,class_id確定先生uid
select user_id
from lessons
left join book on lessons.lesson_id = book.lesson_id
where lessons.class_id = 2
and book.id = 1
group by user_id;

 
book_によるとid,class_id,semester_id確定先生uid
select user_id
from lessons
left join book on lessons.lesson_id = book.lesson_id
where lessons.class_id = 2
and book.id = 1  and
semester_id = 2
group by user_id;

分析:sqlを書くには頭の中で多くのことを考えなければならない.合理性~条件によって、何を得るか~どこから得るか~
 
タイトル:
user表氏名年齢性別出身日name age sex birth_daya 20 b 21 1 c 21 0 d 23 1 e 20 1 sql年齢男性数女性数を書く
SELECT age AS '  ', username AS '  ',SUM(CASE  WHEN sex = '0' THEN 1 ELSE 0 END) AS '  ',SUM(CASE WHEN sex='1' THEN 1 ELSE 0 END) AS '  ' FROM userinfo GROUP BY age