Advertisement

04.29.2008 at 05:10AM PDT, ID: 23361709
[x]
Attachment Details

queries for a 1 to many attribute/value schema

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3
Hi Everyone,

Very much hoping you can help me with 2 queries I am trying to figure out. I have attached a sample set of tables. The schema maps an item to many attribute/values. I have opted to store values in a table where the values are stored as proper datatypes rather than as just varchars which complicates matters.

The attached code features at the bottom the 2 desired result sets I need. In one scenario I am happy to have a row per attribute value per item, whereas in the 2nd I would like a pivot scenario for all attributes.

If anyone can help I'd be very grateful.

Best wishes. AC.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
item i
==============
id | title
--------------
1  | My Item 1
2  | My Item 2
 
 
attributes a
====================
id | name   | type
--------------------
1  | fruit  | varchar
2  | weight | int
 
 
attribute_values av
==========================
id | val_varchar | val_int
--------------------------
1  | apples      | NULL
2  | banana      | NULL
3  | NULL        | 9
4  | NULL        | 6
 
 
items_attributes_values iav
=================================
item_id | attribute_id | value_id
---------------------------------
1       | 1            | 1
1       | 2            | 3
2       | 1            | 2
2       | 2            | 4
 
 
Desired Result Set 1
========================
i.id | a.name | av.val_?
------------------------
1    | fruit  | apples
1    | weight | 9
2    | fruit  | banana
2    | weight | 6
 
 
Desired Result Set 2
========================
i.id | fruit | weight
------------------------
1    | apples| 9
2    | banana| 6
 
Accepted Solution by ptttr:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-46 / EE_QW_2_20070628