mySQL Newbie
Member
- Joined
- Sep 11, 2009
- Messages
- 52
- Reaction score
- 0
- Points
- 6
is not hard.? Okay, in mySQL command prompt. I write the following:
I create and use a database then i create a table called easy_drinks. Then,
CREATE TABLE easy_drinks(drink_name VARCHAR(20), amount1 DEC(1,1), DEC(2,2) );
After that i insert my data.
INSERT INTO easy_drinks VALUES ( 'peach nectar', 1.0, 1.0);
INSERT INTO easy_drinks VALUES ( 'GreyHound', 6.0, 0.75);
INSERT INTO easy_drinks VALUES ( 'Soda', 5.0, 2.0);
Now, the problem is when i want to display the content
SELECT * FROM easy_drinks;
It display like this
----------------------------------------------------------------------------------------------
|drink_name| |amount1| |amount2|
----------------------------------------------------------------------------------------------
|Peach Nectar| |0.9| |0.9|
|Grey Hound| |0.9| |0.75|
|Soda| |0.9| |0.9|
-----------------------------------------------------------------------------------------------
It seems that everything except 0.75 is wrong. I write 6.0 it becomes 0.9, EVERYTHING becomes 0.9 except when i write 0.75 on DEC(2,2).
Help!
As is turns out my book called Head First SQL gives me the wrong information.
They said that DEC (3,3) is 3 digits before the comma and 3 digit after comma.
It turns out that in ReALITY DEC (M,D) M is the total number of digits and D is the number of digits following the decimal points.
No wonder my decimals got messed up. I write DEC (1,1) and DEC (3,3).
So it's 1 digit number but have 1 digit after decimal sign (illogical). Lol.
Anyway thanks guys. I got my help from mySQL help command.
Beware of false information from O'Reilly.
I create and use a database then i create a table called easy_drinks. Then,
CREATE TABLE easy_drinks(drink_name VARCHAR(20), amount1 DEC(1,1), DEC(2,2) );
After that i insert my data.
INSERT INTO easy_drinks VALUES ( 'peach nectar', 1.0, 1.0);
INSERT INTO easy_drinks VALUES ( 'GreyHound', 6.0, 0.75);
INSERT INTO easy_drinks VALUES ( 'Soda', 5.0, 2.0);
Now, the problem is when i want to display the content
SELECT * FROM easy_drinks;
It display like this
----------------------------------------------------------------------------------------------
|drink_name| |amount1| |amount2|
----------------------------------------------------------------------------------------------
|Peach Nectar| |0.9| |0.9|
|Grey Hound| |0.9| |0.75|
|Soda| |0.9| |0.9|
-----------------------------------------------------------------------------------------------
It seems that everything except 0.75 is wrong. I write 6.0 it becomes 0.9, EVERYTHING becomes 0.9 except when i write 0.75 on DEC(2,2).
Help!
As is turns out my book called Head First SQL gives me the wrong information.
They said that DEC (3,3) is 3 digits before the comma and 3 digit after comma.
It turns out that in ReALITY DEC (M,D) M is the total number of digits and D is the number of digits following the decimal points.
No wonder my decimals got messed up. I write DEC (1,1) and DEC (3,3).
So it's 1 digit number but have 1 digit after decimal sign (illogical). Lol.
Anyway thanks guys. I got my help from mySQL help command.
Beware of false information from O'Reilly.