编写查询以显示已取消票证的用户名和用户名,并按user_id按升序显示记录。 我的代码:
SELECT u.user_id, name
FROM users u JOIN tickets t
ON u.user_id= t.user_id JOIN
cancellation c
ON t.ticket_id = c.ticket_id
WHERE cancellation_id IN 'cancel'
ORDER BY user_id;
这不会显示任何输出
答案 0 :(得分:0)
联接类型和联接顺序很重要。有关明确说明,请参阅MySQL Join Made Easy。试试这个:
SELECT u.user_id, u.name
FROM cancellation c JOIN tickets t
ON t.ticket_id = c.ticket_id
JOIN users u ON u.user_id= t.user_id JOIN
WHERE cancellation_id='cancel'
ORDER BY u.user_id;
答案 1 :(得分:0)
select u.user_id, u.name
from users u join tickets t
on u.user_id=t.user_id
join cancellation c on t.ticket_id=c.ticket_id
order by u.user_id;
答案 2 :(得分:0)
这肯定会起作用
select u.user_id,u.name
from((users u inner join tickets t
on u.user_id=t.user_id)
inner join cancellation c
on t.ticket_id=c.ticket_id)
where cancellation_id is not null
group by u.user_id,u.name
order by u.user_id;
答案 3 :(得分:0)
select users.user_id,users.name
from users join tickets
ON users.user_id = tickets.user_id
join cancellation on
tickets.ticket_id = cancellation.ticket_id
where cancellation_id is not null
order by user_id
答案 4 :(得分:0)
使用子查询
select
u.user_id,
u.name
from users u
where user_id in
(select
user_id from tickets
inner join cancellation on tickets.ticket_id
= cancellation.ticket_id)
order by user_id asc;