1
I have the following database table:
*Table structure for table `resultados` */
DROP TABLE IF EXISTS `resultados`;
CREATE TABLE `resultados` (
`cpf` varchar(14) NOT NULL,
`nome` varchar(255) DEFAULT NULL,
`codcurso` int(5) DEFAULT NULL,
`nota` float DEFAULT NULL,
PRIMARY KEY (`cpf`)
);
/*Data for the table `resultados` */
insert into `resultados`(`cpf`,`nome`,`codcurso`,`nota`) values
('123.456.789-01','Alexandre Mie Lopes Mesa',78,4.21),
('123.876.332-72','Maria Ximenes Rosa',1,9.16),
('222.333.444-55','Livia Fernandes Linderberg',43,9.87),
('232.234.789-77','Karol Linderberg',43,8.92),
('289-890-912-76','Pedro Solano Susp',16,4.21),
('345.678.900-37','Amilton Pedro da Silva',78,9.98),
('432.654.987-21','Julio Martinez Silva',21,7.34),
('454.098.123-45','Luiz Henrique de Souza',1,7.35),
('765.123.098-22','Juliana Lopes Alves',22,5.67),
('903.201.871-23','Luiz Peres Lopes',16,8.77),
('987.654.321-10','Ana Alves de Souza',78,9.12);
And I want to select the minimum value, when I use only:
SELECT min(nota) AS menor FROM resultados
I get the result (4.21), but if I want to create a table, with students with lower grades I can’t get such a table
SELECT * FROM resultados WHERE nota = 4.21
I also tried to save this value as float and pass as var but it was not possible, I could only do with the following code:
SELECT * FROM resultados WHERE nota like '" + menorR + "'"
where less R = 4.21
Soon I want to understand why the Where note = (float number) did not work
Instead of using float because you don’t use decimal?
\note` DECIMAL(10,2) DEFAULT NULL`, for example– Jorge B.
SELECT * FROM results WHERE note = (SELECT min(note) AS minor FROM results) what returns ?
– Motta
@Jorgeb. Out of curiosity: What is the difference of
FloatandDecimal?– user7261
@Andrey - Decimal stores the exact value.. ex: 4.21... With float/double (floating point), it could store something like 4.2099999... i.e.. in the future, you may have some problems with rounding.
– emanuelsn
@Andrey The difference is accuracy of the numbers that are saved. With
Floatdoes not guarantee the accuracy of the numbers. WithDecimalensures accuracy but loses decimal places. Soen fountain– Jorge B.