Get the App
SLTechnology News&Howtos  ›  Database  › 

5. SQL quot;01"-query & SQL course comparison & quo

Shulou Source: shulou.com Published: 2022-06-01 14:19:53 09月17日 Update

-- taking this example as an example, we first introduce several commonly used table joins. In this example, only left join is used. Others can try-test:

Join within inner join, the result is that both tables contain rows of Sid

-- left join is connected to the left. The result is the Sid in the left table, and the null value null is not found in the right table.

-- right join join to the right. The result is based on the Sid in the right table, and the null value null is not found in the left table.

-- full outer join full external connection, the result is containing two tables of data

Example: inquire about the information and course scores of students with higher scores in "01" than in "02".

-- 1. The first method: connect to the left, query the student information of both '01' and' 02' courses, and then compare, isnull usage, return score if score has a value, and return 0 if score is null

Select a. Score for course '01', c.score [score for course' 02'] from Student a

Left join SC b on a.Sid=b.Sid and b.Ciddance 01'

Left join SC c on a.Sid=c.Sid and c. Ciddance 02'

Where b.score > isnull (c.scorePhone0)

2. The second way of writing

Select a.*, b.score [score for course '01'], c.score [score for course' 02'] from Student a, SC b, SC c

Where a.Sid = b.Sid and a.Sid = c.Sid and b.Cid = '01' and c.Cid =' 02' and b.score > c.score

Tags: Courses scores results queries examples information students two writing at the same time commonly used grades data methods attempts tests Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Apple Shulou Information OPPO Reno