Im currently trying to get the percentage difference from the same column, but with different dates.
This is the query I'm currently testing:
curr.senaste * 100 / NULLIF(prev.senaste, 0) as percentage
FROM aktier AS curr
INNER JOIN aktier AS prev
ON curr.slug = prev.slug
WHERE date(prev.timestamp) = '2015-11-16'
AND date(curr.timestamp) = CURDATE()
AND curr.slug = 'abb-ltd'
If i run this query i will get the result: 103.14465408805032
But, if I run query
SELECT senaste FROM aktier WHERE slug = 'abb-ltd'i get theses two values:
And when i run
1-(159,4/164,1) on my calculator i will get this result:
Whats wrong with the current set up? And: how do i get the result from the query to show 2,9%?
The column senaste is a
senaste is a
VARCHAR(5) containing data like
VARCHAR fields should not be used to store numbers, especially if you intend on having MySQL run math on the values.
You should instead be using a
DECIMAL(10,1) (assuming you only want a single decimal digit) and you should be using a period, not a comma in your number format. (eg,