3eta: (Default)
[personal profile] 3eta
SQL-оведы, помогите. Нужно сделать запрос, где мне очень хочется вставить цикл, но ведь наверное нельзя?
Звучит просто: выбрать из таблицы с именами и фамилиями людей, у которых фамилия такая же как у кого-либо другого имя. Все идеи закончились, ничего не работает (в том числе по каким ключевым словам гуглить возможные решения).

Date: 2012-09-29 08:58 pm (UTC)
From: [identity profile] 3eta.livejournal.com
Вот еще один похожий:
Many times, a son has the same name as his father. (George Abbott had a son named George.) Find all such pairs, and list their names, the father's birth date, and the son's birth date.

Получается только выбрать всех, у кого в принципе есть отцы (father.person.id), а вот как смэтчить с именами отцов - не понимаю.

Date: 2012-09-29 10:51 pm (UTC)
From: [identity profile] jgofri.livejournal.com
А как определяется, кто чей отец? Is there a recursive relationship in that table?

Date: 2012-09-29 10:52 pm (UTC)
From: [identity profile] 3eta.livejournal.com
да, таблица выглядит как
Person_ID
First_Name
Last_Name
...
Father_Person_ID
Mother_Person_ID

Date: 2012-09-29 11:06 pm (UTC)
From: [identity profile] jgofri.livejournal.com
I may be rusty on the syntax, but I think something like this will work:

select t1.last_name, t1.first name, t1.dob "son dob", t2.dob "dad dob"
from Table t1, Table t2
where t1.father_person_id = t2.person_id
and t1.first_name = t2.first_name

Profile

3eta: (Default)
3eta

September 2021

S M T W T F S
   1234
567891011
12131415161718
19 202122232425
2627282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 6th, 2025 02:48 am
Powered by Dreamwidth Studios