Objects,Properties,Data

Hello
I need a little help.

use [master]
go
create database [human]
go
use [human]
go
create table [Objects]
(
 ID int not null identity primary key,
 name varchar(20) not null,

)

create table [Properties]
(
 ID int not null identity primary key,
 name varchar(20) not null,

)

create table [Data]
(
 ObjectID int not null identity primary key,
 PropertyID int not null,
 Value varchar(20) not null,

)
go
use [human]
insert into Objects(name) values('Ahmet')
insert into Objects(name) values('Hasan')
insert into Properties(name) values('Göz Rengi')
insert into Properties(name) values('Boyu')

insert into Data(PropertyID,Value) values(1,'Mavi')
insert into Data(PropertyID,Value) values(2,'1.70')
insert into Data(PropertyID,Value) values(1,'Yeşil')
insert into Data(PropertyID,Value) values(2,'1.90')

ekr

How should I write a sql query with the result in the picture?

I think there is something wrong with your data model. Are you sure that objectID in the data table is an identity primary key?

You can only get the result if you insert this into Data:

insert into Data(ObjectID,PropertyID,Value) values(1,1,'Mavi')
insert into Data(ObjectID,PropertyID,Value) values(1,2,'1.70')
insert into Data(ObjectID,PropertyID,Value) values(2,1,'Yeşil')
insert into Data(ObjectID,PropertyID,Value) values(2,2,'1.90')

create database [human]
go
use [human]
go
create table [Objects]
(
 ID int not null identity primary key,
 name varchar(20) not null,

)

create table [Properties]
(
 ID int not null identity primary key,
 name varchar(20) not null,

)

create table [Data]
(
 ObjectID int not null identity primary key,
 PropertyID int not null,
 Value varchar(20) not null,

)
go
use [human]
insert into Objects(name) values('Ms.Ahmet')
insert into Objects(name) values('Ms.Musa')
insert into Properties(name) values('Eye Color')
insert into Properties(name) values('Length')

insert into Data(PropertyID,Value) values(1,'Blue')
insert into Data(PropertyID,Value) values(2,'1.70')
insert into Data(PropertyID,Value) values(1,'Green')
insert into Data(PropertyID,Value) values(2,'1.90')

A "select" clause is required to give the result in the image.

hi

hope this helps

i have to work on getting the Goz Rengi as column name

select 
     a.name 
	 , c.mx
	 , c.mn  
from 
    [Objects] a 
	   join 
	[Properties] b on a.ID = B.Id 
	  join 
	(select floor(OBJECTId-1)/2 as grp , min(Value) as mn,max(value)  as mx from Data group by floor(OBJECTId-1)/2 ) c on b.Id= c.grp+1

image

harishgg1
Thank you very much. :pray::pray::pray::pray::pray::pray::pray::pray::pray: