![]() | |
#1
| |||
| |||
|
|
Black|Cyan|Green|Magenta|Orange ----------+-----+----+-----+-------+------- |
#2
| |||
| |||
|
|
I want to make a feature table but not quite sure how to design my table. As a hypothetical example imaging a group of cars. Audi BMC Chevrolet Datsun Envoy Ford GM . . . VW And imagine a list of colors Black Cyan Green Magenta Orange So I want to make a two dimensional table where where the rows are the type of car and the columns are the colors. ------------------------------------------- |Black|Cyan|Green|Magenta|Orange ----------+-----+----+-----+-------+------- Audi | Y | N | Y | N | N BMC | Y | N | Y | N | Y Chevrolet | Y | N | Y | N | Y Datsun | Y | N | Y | N | Y Envoy | N | N | Y | N | Y Ford | Y | N | N | N | N GM | N | Y | Y | N | Y Hyundai | Y | Y | Y | N | N VW | Y | Y | Y | Y | Y Y means the car is available in the color N means it's not. I have a table that has a list of Car Names and a Table that is a list of colors. Now what is the structure of the table that is the 'feature' table? |
#3
| |||
| |||
|
|
I want to make a feature table but not quite sure how to design my table. As a hypothetical example imaging a group of cars. Audi BMC Chevrolet Datsun Envoy Ford GM . . . VW And imagine a list of colors Black Cyan Green Magenta Orange So I want to make a two dimensional table where where the rows are the type of car and the columns are the colors. ------------------------------------------- |Black|Cyan|Green|Magenta|Orange ----------+-----+----+-----+-------+------- Audi | Y | N | Y | N | N BMC | Y | N | Y | N | Y Chevrolet | Y | N | Y | N | Y Datsun | Y | N | Y | N | Y Envoy | N | N | Y | N | Y Ford | Y | N | N | N | N GM | N | Y | Y | N | Y Hyundai | Y | Y | Y | N | N VW | Y | Y | Y | Y | Y Y means the car is available in the color N means it's not. I have a table that has a list of Car Names and a Table that is a list of colors. Now what is the structure of the table that is the 'feature' table? |
#4
| |||
| |||
|
|
On Friday, December 9, 2011 11:09:37 PM UTC-5, SpreadTooThin wrote: I want to make a feature table but not quite sure how to design my table. As a hypothetical example imaging a group of cars. Audi BMC Chevrolet Datsun Envoy Ford GM . . . VW And imagine a list of colors Black Cyan Green Magenta Orange So I want to make a two dimensional table where where the rows are the type of car and the columns are the colors. ------------------------------------------- |Black|Cyan|Green|Magenta|Orange ----------+-----+----+-----+-------+------- Audi | Y | N | Y | N | N BMC | Y | N | Y | N | Y Chevrolet | Y | N | Y | N | Y Datsun | Y | N | Y | N | Y Envoy | N | N | Y | N | Y Ford | Y | N | N | N | N GM | N | Y | Y | N | Y Hyundai | Y | Y | Y | N | N VW | Y | Y | Y | Y | Y Y means the car is available in the color N means it's not. I have a table that has a list of Car Names and a Table that is a list of colors. Now what is the structure of the table that is the 'feature' table? Off the top of my head, I would probably make the table with 2 columns: car_type, and color. Set each to be a varchar(20) (assuming that you don't have a car or color more than 20 characters in length). Then, have a bunch of rows, like: Audi | black Audi | green BMW | black And so on. This way, in whatever program you're using, you would SELECT color FROM table WHERE car_type='Audi' (or whatever), then load the result into an array. |
#5
| |||
| |||
|
|
I want to make a feature table but not quite sure how to design my table. As a hypothetical example imaging a group of cars. Audi BMC Chevrolet Datsun Envoy Ford GM . . . VW And imagine a list of colors Black Cyan Green Magenta Orange So I want to make a two dimensional table where where the rows are the type of car and the columns are the colors. ------------------------------------------- |Black|Cyan|Green|Magenta|Orange ----------+-----+----+-----+-------+------- Audi | Y | N | Y | N | N BMC | Y | N | Y | N | Y Chevrolet | Y | N | Y | N | Y Datsun | Y | N | Y | N | Y Envoy | N | N | Y | N | Y Ford | Y | N | N | N | N GM | N | Y | Y | N | Y Hyundai | Y | Y | Y | N | N VW | Y | Y | Y | Y | Y Y means the car is available in the color N means it's not. I have a table that has a list of Car Names and a Table that is a list of colors. Now what is the structure of the table that is the 'feature' table? use two three tables |
#6
| |||
| |||
|
|
On Friday, December 9, 2011 11:55:29 PM UTC-5, Jason C wrote: On Friday, December 9, 2011 11:09:37 PM UTC-5, SpreadTooThin wrote: I want to make a feature table but not quite sure how to design my table. As a hypothetical example imaging a group of cars. Audi BMC Chevrolet Datsun Envoy Ford GM . . . VW And imagine a list of colors Black Cyan Green Magenta Orange So I want to make a two dimensional table where where the rows are the type of car and the columns are the colors. ------------------------------------------- |Black|Cyan|Green|Magenta|Orange ----------+-----+----+-----+-------+------- Audi | Y | N | Y | N | N BMC | Y | N | Y | N | Y Chevrolet | Y | N | Y | N | Y Datsun | Y | N | Y | N | Y Envoy | N | N | Y | N | Y Ford | Y | N | N | N | N GM | N | Y | Y | N | Y Hyundai | Y | Y | Y | N | N VW | Y | Y | Y | Y | Y Y means the car is available in the color N means it's not. I have a table that has a list of Car Names and a Table that is a list of colors. Now what is the structure of the table that is the 'feature' table? Off the top of my head, I would probably make the table with 2 columns: car_type, and color. Set each to be a varchar(20) (assuming that you don't have a car or color more than 20 characters in length). Then, have a bunch of rows, like: Audi | black Audi | green BMW | black And so on. This way, in whatever program you're using, you would SELECT color FROM table WHERE car_type='Audi' (or whatever), then load the result into an array. I guess I should add that, instead of making them VARCHARs, you could make them an ENUM field, and specify the options in the beginning. MySQL states that this is faster to query, but I just made that modification to a table with 4 million rows, and the speed increase was by 0.001 seconds. I changed it back so that it would be easier to add new options in the long run. |
#7
| |||
| |||
|
|
On Friday, December 9, 2011 11:55:29 PM UTC-5, Jason C wrote: [...] I guess I should add that, instead of making them VARCHARs, you could make them an ENUM field, |
![]() |
| Thread Tools | |
| Display Modes | |
| |