2

我是 SQL 新手,我需要一些帮助,

我想用姓氏找出已确认(已确认=1)的预订日期Steven

有人可以帮助这个 SQL 查询吗

表成员

+-----------+-----------+
|Member_id  | last_name |
+-----------+-----------+
| 1         | David     |
| 2         | owen      |
| 3         | Tom       |
| 4         | Steven    |
| 5         | Steven    |
| 6         | Steven    |
| 7         | Steven    |
| 8         | Steven    |
| 9         | Steven    |
+-----------+-----------+

表保留

+-----------+-----------+-----------+-----------+
|resvationID|Member_id  | day       |   month   |
+-----------+-----------+-----------+-----------+
| 1         | 1         |   1       |     6     |
| 2         | 1         |   2       |     6     |
| 3         | 2         |   1       |     6     |
| 4         | 4         |   1       |     6     |
| 5         | 4         |   2       |     6     |
| 6         | 5         |   1       |     6     |
| 7         | 5         |   2       |     6     |
| 8         | 7         |   3       |     6     |
+-----------+-----------+-----------+-----------+

确认

+-----------+-----------+-----------+
|confirmID  |resvationID| confirmed |
+-----------+-----------+-----------+
| 1         | 1         |   1       |
| 2         | 2         |   1       |
| 3         | 3         |   0       |
| 4         | 4         |   0       |
| 5         | 5         |   1       |
| 6         | 6         |   1       |
| 7         | 7         |   0       |
| 8         | 8         |   1       |
+-----------+-----------+-----------+
4

3 回答 3

3

这样的事情对你有用吗?

 SELECT
     m.Member_ID, m.Last_Name,
     r.Day, r.Month, 
     c.ConfirmID
 FROM 
     table_member m
 INNER JOIN 
     table_reservation r ON r.Member_ID = m.Member_ID
 INNER JOIN
     Confirm c ON c.resvationID = r.resvationID
 WHERE
     m.Last_Name = 'Steven' AND c.confirmed = 1
于 2012-12-22T18:22:04.820 回答
0
Select c.*, r.*, m.*
from confirm c
left join table_reservation r on c.reservationID = r.reservationID
left join table_member m on m.member_id = r.Member_id
Where c.confirmed = 1
and m.name = "Steven"

我没有测试它,但这应该为您指明方向。

(编辑:第二个“哪里”是错字)

于 2012-12-22T18:20:12.310 回答
0

对所有表应用内连接

select day,month from table_reservation inner join table_member on table_member.member_id=table_reservation.member_id
inner join confirm on confirm.reservationid=table_reservation.reservationid where confirm.confirmid=1
and table_member.last_name like 'Steven'
于 2012-12-22T20:23:27.520 回答