Mysql - How to find max Value with decimal [closed] - mysql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
In the mysql table (books_title) have 144 records.
The column book_progressive contain this values for rows:
01.01
02.01
03.01
...
99.01
100.01
101.01
102.01
...
144.01
When check the max value with this query:
select max(book_progressive) from books_title
return 99.01, but the max value is 144.01.
How to resolve this?
Thanks

It looks like your book_progressive is declared as CHAR/VARCHAR and not DECIMAL.
Change your column type , or CAST the result :
select max(CAST(book_progressive AS DECIMAL(10,2)) from books_title

I find a Solution with LPAD because the max value is found only if the number of characters is equal
select max(lpad(book_progressive,6,0)) from books_title
Thans

Related

Error Code: 1525. Incorrect DATE value using STR_TO_DATE [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
why do I receive this error:
Error Code: 1525. Incorrect DATE value: '01-01-2017'
When using this query:
CREATE VIEW 2017Employees AS
SELECT EmployeeID
FROM contract
WHERE `Start` <= STR_TO_DATE('01-01-2017','%d-%m-%y')
AND DueFinish>= STR_TO_DATE('31-12-2017','%d-%m-%y');
I thought that the function STR_TO_DATE converted strings to dates.
You have to use %Y instead of %y because you are using year with four digits:
CREATE VIEW 2017Employees AS
SELECT EmployeeID
FROM contract
WHERE `Start` <= STR_TO_DATE('01-01-2017','%d-%m-%Y')
AND DueFinish>= STR_TO_DATE('31-12-2017','%d-%m-%Y');
You can find all available format specifier with a explanation on the documentation of DATE_FORMAT:
%Y - Year, numeric, four digits
%y - Year, numeric (two digits)

How can I add values into MySQL if the value is either string or float? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am parsing an excel file and adding the values im getting into a database. But one of the columns I am parsing can be either a float or a string. Like such: 0,45 or Contact Support. What is the best way for me to add this as it is, to my database? Or more how should I format my database column for this?
use varchar datatype(in MySQL) for the column you want to parse and you can save both the integer and character values.
I recommend you create a float type column and a varchar column. Write your parser so that valid float values are filled to the float column and the rest to the varchar one. This will allow you to both sort your database by the value of the float type column and run queries on fields that are missing that value: SELECT * FROM mytable WHERE myfloat IS NULL
first am with Kaivosukeltaja answer.
but if you can't do that, make a varchar column to save the strings or doubles.
BTW when you get data from a database all the data comes in string format then you can cast it to any type you want.
if you are using PHP:
$x = $row['string_double_column'];
if(is_numeric($x))
return doubleval($x);
else
return $x;

Find all entries that contain more than one colon character [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to find all entries that contain more than one colon (:) character.
However when I do LIKE %:% it shows the entire table because of http://. How can I find more than one colon?
SELECT *
FROM `downloads`
WHERE `url` LIKE '%:%'
LIMIT 0 , 30
If you want to find a colon that occurs after the scheme of your URL, then change your LIKE clause accordingly:
SELECT *
FROM `downloads`
WHERE `url` LIKE '%:%:%'
LIMIT 0 , 30
The first colon will be in your scheme, and the second will be somewhere else in the Url after the scheme.
A word of caution, however - it is completely valid to have a colon in the Url when a port number is specified, e.g.: http://localhost:8080

Append $ character to a MySQL DB field so that length is increased by 40 % [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I want to append any character, say $, to the name of the student field in database such that its length is increased by 40 %, and save the result in the database.
E.g.:
Name: VijayKumar
After update:
Name: VijayKumar$$$$
You would use concat() and repeat():
select concat(name, repeat('$', ceil(length(name) * 0.4))

how to select the result using REGEXP in mysql,not contain a string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
MySQL does not support the Negative Lookahead. How can I find the result not containing a string using REGEXP.
I am using 'NOT REGEXP' but the result is unexpected.
there is a 'Content' column in my table,i want to find the rows which the Content column contains '' label,but i still want some src to be excluded.
here is the sql:
Content REGEXP '.' AND Content NOT REGEXP '.(test.mywebsite1.com/|img.mywebsite.com/face/|test.mywebsite.com/phoneIcon.jpg).*'
but when the Content contain both and it works unexpected;
Test your REGEXP on a known set, get that working, and verify it is working.
Then add the NOT to get the boolean inverse.
Note that a MySQL boolean expression will return one of three possible values: TRUE, FALSE and NULL.
And note that NOT expr will also return one of three possible values: TRUE, FALSE and NULL.
When expr returns NULL, then NOT expr will also return NULL.
It's not really productive to attempt to provide any other assistance, absent an actual question and more details of what you are attempting to do.