SQL: Счастливые билеты

Под катом запрос MySQL для получения списка счастливых билетов без использования временных таблиц.
select * from
	(select 0 as a union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) a
join
	(select 0 as b union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) b
	on 1=1
join
	(select 0 as c union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) c
	on 1=1
join
	(select 0 as d union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) d
	on 1=1
join
	(select 0 as e union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) e
	on 1=1
join
	(select 0 as f union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) f
	on 1=1
where 
	a+b+c = d+e+f;

Leave a Reply

Your email address will not be published. Required fields are marked *