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

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 Aug. 21st, 2025 03:51 pm
Powered by Dreamwidth Studios