HosseinProgrammer
یک شنبه 14 اسفند 1390, 16:52 عصر
با سلام و خسته نباشید
یک سوال دارم.
دو تا جدول بصورت زیر دارم :
reshteh
Reshteh Code
Computer 1
Mechanic 2
gerayesh
gerayesh Code
Hard 1
Soft 1
Sayalat 2
Jamedat 2
میخوام خروجی بصورت روبرو باشه (تمام گرایش ها در سطر همان رشته بیاید) :
خروجی مطلوب
gerayesh gerayesh Reshteh Code
Soft Hard Computer 1
Jamedat Sayalat Mechanic 2
ولی بصورت روبرو میشه :
خروجی فعلی
gerayesh gerayesh Reshteh Code
Soft Hard Computer 1
Hard Soft Computer 1
Jamedat Sayalat Mechanic 2
Sayalat Jamedat Mechanic 2
کدی که نوشتم بصورت زیر می باشد :
create table reshteh
(
code int primary key,
reshteh varchar(20)
)
create table gerayesh
(
code int ,
gerayesh varchar (20),
foreign key (code) references reshteh
)
select tb1.code, tb1.reshteh, tb1.gerayesh, tb2.gerayesh
from
(select gerayesh.code ,reshteh,gerayesh
from reshteh,gerayesh where reshteh.code = gerayesh.code) tb1
inner join
(select gerayesh.code ,reshteh,gerayesh
from reshteh,gerayesh where reshteh.code = gerayesh.code) tb2
on tb1.code =tb2.code
where tb1.gerayesh != tb2.gerayesh
نکات :
1) این برای حالتی است که میدانیم که چند تا گرایش برای رشته داریم. (در اینجا دو تا) و در نتیجه یک join استفاده کردیم. در چنین حالتی ، روش چگونه است؟
2) آیا راه حلی برای حالت کلی (رشته ها با تعداد گرایش های مختلف) ، وجود دارد؟ اگر بله ، چگونه ؟
پیشاپیش از وقتی که می گذارید و جوابی که می دهید ، سپاسگزارم.
یک سوال دارم.
دو تا جدول بصورت زیر دارم :
reshteh
Reshteh Code
Computer 1
Mechanic 2
gerayesh
gerayesh Code
Hard 1
Soft 1
Sayalat 2
Jamedat 2
میخوام خروجی بصورت روبرو باشه (تمام گرایش ها در سطر همان رشته بیاید) :
خروجی مطلوب
gerayesh gerayesh Reshteh Code
Soft Hard Computer 1
Jamedat Sayalat Mechanic 2
ولی بصورت روبرو میشه :
خروجی فعلی
gerayesh gerayesh Reshteh Code
Soft Hard Computer 1
Hard Soft Computer 1
Jamedat Sayalat Mechanic 2
Sayalat Jamedat Mechanic 2
کدی که نوشتم بصورت زیر می باشد :
create table reshteh
(
code int primary key,
reshteh varchar(20)
)
create table gerayesh
(
code int ,
gerayesh varchar (20),
foreign key (code) references reshteh
)
select tb1.code, tb1.reshteh, tb1.gerayesh, tb2.gerayesh
from
(select gerayesh.code ,reshteh,gerayesh
from reshteh,gerayesh where reshteh.code = gerayesh.code) tb1
inner join
(select gerayesh.code ,reshteh,gerayesh
from reshteh,gerayesh where reshteh.code = gerayesh.code) tb2
on tb1.code =tb2.code
where tb1.gerayesh != tb2.gerayesh
نکات :
1) این برای حالتی است که میدانیم که چند تا گرایش برای رشته داریم. (در اینجا دو تا) و در نتیجه یک join استفاده کردیم. در چنین حالتی ، روش چگونه است؟
2) آیا راه حلی برای حالت کلی (رشته ها با تعداد گرایش های مختلف) ، وجود دارد؟ اگر بله ، چگونه ؟
پیشاپیش از وقتی که می گذارید و جوابی که می دهید ، سپاسگزارم.