This is long, but you mention that you are a beginner. A couple of observations:
Don't store numeric attributes as VARCHAR. Does the SUM function even work on a string?
Attribute lookup tables are handy, but I recommend using a string as a token rather than a number. The comment in code sample says it all--who is going to know that 3 is OK.
Please read up ...