-- Extazyk,Smokefire,Smokemantra,Муркот,Растафаркрай,Хихихантер
with char1_achievements as (
	select id,
		date,
		completed
	from achievements
	where name = 'Extazyk'
),
char2_achievements as (
	select id,
		date,
		completed
	from achievements
	where name = 'Smokemantra'
),
all_achievements as (
	select id
	from char1_achievements
	union
	select id
	from char2_achievements
)
select all_achievements.id,
	COALESCE(char1_achievements.completed, 0) as char1_completed,
	char1_achievements.date as char1_date,
	COALESCE(char2_achievements.completed, 0) as char2_completed,
	char2_achievements.date as char2_date,
	case
		when char1_achievements.id is null then 'Only in Character2'
		when char2_achievements.id is null then 'Only in Character1'
		when char1_achievements.completed != char2_achievements.completed then 'Completion status differs'
		when char1_achievements.date != char2_achievements.date then 'Dates differ'
		else 'Same'
	end as difference_type
from all_achievements
	left join char1_achievements on all_achievements.id = char1_achievements.id
	left join char2_achievements on all_achievements.id = char2_achievements.id
where char1_achievements.id is null
	or char2_achievements.id is null
	or char1_achievements.completed != char2_achievements.completed
	or char1_achievements.date != char2_achievements.date
order by all_achievements.id;