-1

I have a Different Real Estate Projects Listed In My website.

The Projects are separated as below.

affordable
budget segment 
Luxurious  
affordable & budget segment 
budget segment & Luxurious  
affordable,budget segment &  Luxurious.

I will use the above classification to populate in the similar projects tab in the Project Description page.

For Eg

ProjectName          Class
ProjectA           Affordable
ProjectB           Budget Segment
ProjectC           Affordable & Budget Segment
ProjectD           Budget Segment               
ProjectE           Affordable
ProjectF           Affordable, Budget Segment &  Luxurious 

Now in the Project Description page for ProjectA people should see ProjectC, ProjectE, ProjectF in Similar Projects Tab Since ProjectA is Affordable and ProjectC, ProjectE, ProjectF contains houses under Affordable Segment.

Suggest me a Single Column table Structure to the above Requirement and a query to get Similar Projects.

Thank You

4

1 回答 1

0

同意上面的评论,你应该使用一对多的关系。如果您必须将其仅作为一列,则:

为这些中的每一个分配一个 int 值,并使用numeric+来存储按位 AND ( &) 来检索不同的组合。

Affordable = 1
Budget Segment = 2
Luxurious = 4         # Note: it's Four, not Three.

请注意4+2+1=7. 将其存储proj_valproj_description表中。

将这些值放入您的项目列表中:

ProjectName        Class                            int val
-----------        -----                            -------
ProjectA           Affordable                             1
ProjectB           Budget Segment                         2
ProjectC           Affordable & Budget Segment        1+2=3
ProjectD (=ProjB)  Budget Segment                         2
ProjectE (=ProjA)  Affordable                             1
ProjectF           Affordable, Budget & Luxurious   1+2+4=7
no Proj ?          Luxurious                              4
........           Affordable + Luxurious             1+4=5
........           Budget + Luxurious                 2+4=6

要获得项目 A 的相似项,请执行以下操作:

SELECT * FROM `proj_description` WHERE `proj_val` & 1 != 0

根据1上表计算。所以 Proj C ( proj_val=3) 将给出 Proj F 作为结果:3 & 7 = 3它不为零。

于 2012-08-29T10:25:16.197 回答