Frequently Used database interview questions

Source: Internet
Author: User

Answer:

-- 1
Select * from students where Sid in
(Select r_sid from sresult where r_cid = (select CID from course where cname = 'tax basis '))
-- 2
Select * from students where Sid in
(Select r_sid from sresult where r_cid = 2)
-- 3
Select * from students where sid not in
(Select r_sid from sresult where r_cid = 5)
-- 4
Select * From DBO. Students where Sid in
(
Select r_sid from sresult group by r_sid having count (*) =
(Select count (*) from course)
)
-- 5
Select count (distinct r_sid) from sresult
-- Select count (*) from
-- (Select r_sid from sresult
-- Group by r_sid)
-- 6

Select * From DBO. Students where Sid in
(
Select r_sid from sresult group by r_sid having count (*)> 5
)

 

Answer:

-- 1
Select * from students where st_id in
(Select r_stid from results where r_tid not in
(Select t_id from DBO. Teachers where t_name = 'lilim '))
-- 2
Select a. st_name, B. fenshu from students,
(Select r_stid, AVG (r_fenshi) as fenshu from results where r_fenshi <60 group by r_stid having count (*)> = 2) B
Where a. st_id = B. r_stid
-- 3

Select * from students where st_id in
(
Select r_stid from results where r_tid in
(Select t_id from teachers where t_lesson = 'mate' or t_lesson = 'English ')
Group by r_stid having count (*) = 2
)
-- 4
Select r_stid from results
Where r_fenshi>
(Select r_fenshi from DBO. Results where r_tid = 't001' and r_stid = 'st002 ')
And r_tid = 't001'

-- 5
-- Select * From DBO. Students
-- Select * From DBO. Teachers
Select * from (select * From results where r_tid = 't001') A, (select * From results where r_tid = 't002') B
Where
A. r_stid = B. r_stid
And a. r_fenshi> B. r_fenshi

-- Select * From results where (r_tid = 't001' or r_tid = 't002') and r_stid in ('st001', 'st002', 'st002') order by r_stid
-- Select * From results where r_tid = 't002 'order by r_stid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.