I have a table of data in excel that looks like this:
I need to get this data imported into an SQL table.
Eventually I need to be able to query the table by saying something like:
Select the value where x-axis equals 762 and y-axis equals 889 - this should return 30.60.
What is the best way to represent this data in an SQL table to make it easy to query?
Advertisement
Answer
What is the best way to represent this data in an SQL table to make it easy to query?
The answer quite lies in your pseudo code. The most relevant way to store your data is in a table with three columns: x
and y
, and value
, and a unique constraint on the first two columns.
the dataset provided in your example would translate as follows:
x y value ---------------- 762 635 26.23 762 762 28.41 762 889 30.60 1016 635 27.61 1016 762 29.91 1016 889 32.31 1270 635 29.06 1270 762 31.48 1270 889 33.91
Select the value where x-axis equals 762 and y-axis equals 889 – this should return 30.60.
With this table structure, that’s a simple query now:
select value from mytable where x = 762 and y = 889