example of 2NF and 3NF normalization - database-normalization

I understand the normalization concept, especially the first normal form (1NF), but not 2NF and 3NF.
How does one convert the sample table below to 2NF and 3NF?
Prod_id prod_name prod_type prod_price
1 HP Laptop 200
2 Adidas Clothing 100
3 Samsung Phone 300
3 Samsung Television 500

Here are some examples:
example 1: 2FN;
suppose we have this registry(numStudent,nameStudent ,codeModule) table ;
this is not in 2NF because of this dependancy :
(numStudent,codeModule) is a candidate key for registry table but we have
numStudent-> nameStudent so normalize we simply provide registry(numStudent,codeModule)
example 2: 3FN
suppose we have this customer(numCustomer,city,country) tatble ; this is not in 3FN
because : city->country
so to correct that ,we'll do this one
R1(numCustomer,city) and R2(city,country)

Related

use algorithm to generate decompositions in 3NF

I would like to use the algorithm to generate decompositions in 3NF
with retention of dependencies.
R(ABCDEFGH)
F={a->b, abcd->e,ef->g,ef->h,acdf->e,acdf->g}
the only key is acdf. I apply the algorithm to find the 3fn,
eliminating extraneous attributes and redundant dependencies. I get:
F={a->b, acd->e, ef->g, ef->h}
if I create these tables:
tab1 (AB)
tab2 (ACDE)
tab3 (EFG)
TAB4 (EFH)
Am I in normal third form? No. it seems to me that I can't
never decompose it into a 3fn because of a-> b.
So what does that mean, that the algorithm isn't sure which I am
do you find a decomposition in 3 fn?

Tableau - Name Rank, by State / Year / Gender

I have a data set downloaded from the Social Security website. The data is in the form below, and contains the popularity (i.e., as defined by Count) of names, by gender, year and state:
State Gender Year Name Count First Letter
AK F 1910 Anna 10 A
AK F 1910 Annie 12 A
AK F 1911 Annie 6 A
AK F 1912 Alice 5 A
AK M 1912 Wilbur 7 W
AK M 1912 Thomas 7 T
Within Tableau, I'd like to Top X names by each of these categories (or all if not filters are applied). However, when I use a Top filter in a visualization, the underlying data produced by the filter is the form:
For example, I need the first ranked name, and be able to use filters to see how that changes by year, gender, and state. I'm thinking this might be accomplished by an LOD expression, but not sure where to start.
You can achieve this without needing a LOD calculation. Simply change your filters from standard blue dimension filters to be context filters. To do this simply right click on the filter when it is in the filter pane and click "Add to Context". The filter will be shown as grey. Now all ranks will be calculated after filters have been apllied
Why does this work? It is to do with the Order of Operations in Tableau. A calculation such as rank is a table calculation. As the name implies the calculation is processed on the entire data table before dimension filters are applied. However, when something is a context filter it creates temporary tables which are then used to calculate table cals.
Find out more here: https://www.google.com.au/search?q=order+of+operations+tableau&oq=order+of+operations+tableau&aqs=chrome..69i57j0j69i65j0j69i65j0.3475j0j7&sourceid=chrome&ie=UTF-8

How to merge pair-wise table(s) and non-pairwise table(s) in MatLab?

I am trying to perform clustering analysis. I have extracted all the possible data. And have made several pairwise comparisons. Now I want to know how do I merge the data?
Table 1:
entry smth coefficient
entry1 smth1 1.23
entry2 smth1 2.05
entry3 smth2 0.95
entry2 smth4 1.65
Table 2:
smth
smth1 smth2 smth 4
smth1 100 59 35
smth2 59 100 82
smth4 35 82 100
Table 3:
entry
entry1 entry2 entry3
entry1 100 82 75
entry2 82 100 59
entry3 75 59 100
I am trying to understand how to program this. I am new to matlab, I am training a lot, so there's definitely some progress, but now enough to get how to solve my problem.
UPDATE:
Here is the illustration to the table 2:
There is some similarity and difference between different smths.
Now here is the illustration to the table 3:
Entries also have some relational distance.
I also have input cases - table 1. Each row of the table is a unique input case. However, the real table is long, so some of the cases may be actually the same, though named differently. Now, I want to combine pairwise comparison 1, pairwise comparison 2 and if required up to pairwise comparison n. Finally, there are also some non-relative parameters (in table 1 there's one only - called coefficient), by which I want to multiply the position of pairwise-verified point in space (i.e. I am introducing a new axis - corresponding to coefficient and move the points by this axis. So there will be some sort of distribution, which I will be able to use in clustering analysis. I.e. I have an axis1/plane1 - corresponding to the pairwise comparisons of the smths, I have an axis2/plane2 - pairwise comparisons of the entries. Then I apply all those to the cases, for example in table 1 entry2 and smth1 appear more than twice. I know relational distance of entry2 vs other entries, as well as a relational distance of smth1 vs other smths, now I want to combine them into all the cases, given in table 1 and to move the point by axis3 - non-relational axis, corresponding to parameter coefficient.

Create a new variable in Tableau

I am new to Tableau and trying to get myself oriented to this system. I am an R user and typically work with wide data formats, so getting things wrangled into the proper long format has been tricky. Here is my current problem.
Assume I have a data file that is structured as such
ID Disorder Value
1 A 0
1 B 1
1 C 0
2 A 1
2 B 1
2 C 1
3 A 0
3 B 0
3 C 0
What I would like to do is to combine the variables, such that the presence of a set of disorders are used for summary variables. For example, how could I go about achieving something like this as my output? The sum is the number of people with the disorder, and the percentage is the number of people with the disorder divided by the total number of people.
Disorders Sum Percentage
A 1 33.3
B 2 66.6
C 1 33.3
AB 2 66.6
BC 2 66.6
AC 1 33.3
ABC 2 66.6
The approach to this would really be dependent on how flexible it has to be. Ultimately a wide data source with your Disorder making columns would make this easier. You will still need to blend the results on a data scaffold that has the combinations of codes you are wanting to get this to work in Tableau. If this needs to scale, you'll want to do the transformation work using custom SQL or another ETL tool like Alteryx. I posted a solution to this question for you over on the Tableau forum where I can upload files: http://community.tableausoftware.com/message/316168

Cumulative min on earlier versions of PostgreSQL

I am using PostgreSQL 8.2, which is main reason why I'm asking this question. I want to get in this version of PostgreSQL a column (let name it C) with cumulative minimum for some other preordered column (let name it B). So on n-th row of column C should be minimum of values of B in rows 1 to n for some ordering.
In example below column A gives order and column C contains cumulative minimum for column B in that order:
A B C
------------
1 5 5
2 4 4
3 6 4
4 5 4
5 3 3
6 1 1
Probably easiest way to explain what I want is what, in later versions, next query does:
SELECT A , B, min (B) OVER(ORDER BY A) C FROM T;
But version 8.2, of course, don't have window functions.
I've written some plpgsql functions that do this on arrays. But to use this I have to use array_agg aggregate function that I again wrote myself (there no built in array_agg in that version). This approach isn't very efficient and while it worked well on smaller tables it becoming almost unusable now that I need to use it on bigger ones.
So I would be very grateful for any suggestions of alternative, more efficient solutions of this problem.
Thank you!
Well, you can use this simple subselect:
SELECT a, b, (SELECT min(b) FROM t t1 WHERE t1.a <= t.a) AS c
FROM t
ORDER BY a;
But I doubt it will be faster for big tables than a plpgsql function. Maybe you can show us your function. There might be room for improvement there.
For this to be fast you should have a multi-column index like:
CREATE INDEX t_a_b_idx ON t (a,b);
But really, you should upgrade your to a more recent version of PostgreSQL. Version 8.2 has reached end of life last year. No more security updates. And so many missing features ...