Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data (xkcd: ISO 8601). We need to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL.
And you need to read and download the PDF for: https:--www.simple-talk.com-books-sql-books-119-sql-code-smells-
have columns vague_generic_name, something_lower_limit, something_upper_limit, a_value and n_value. <<
But because you have no manners, we have no such information! βnameβ of what? Upper and lower limits of what? I will assume that a_value and n_value are standard terms in your trade, so they make sense.
I have created a new column result1 which is the difference between a_value and n_value <<
Why? This just wastes time and space. Do it as a computation in a VIEW or query.
ALTER TABLE Foobar ADD result1 AS (a_value - n_value);
I created a new Column called "In/Out" [sic] which is CASE statement [sic: this is an expression, not a statement]. Did you really use a slash in a data element name?
(CASE WHEN (a_value - n_value) >= lower_something_limit
AND (a_value β n_value]) <= lower_something_limit
THEN 1 ELSE 0 END) AS silly_flag
Please remember 5-th grade math. Reduce the inequalities:
(a_value β n_value) = lower_something_limit;
Did you mean:
(CASE WHEN (a_value - n_value)
BETWEEN lower_something_limit AND upper_something_limit
THEN 1 ELSE 0 END) AS silly_flag
This is still bad SQL, but at least the math is right.
Now I need to create a third column called "percentage" which will give me the something_percentage of values inside the limit <<
Not in SQL! We are happy with virtual, computed columns. No more tapes and punch cards in RDBMS.
Since you were too rude to post DDL, you might have done INTEGER math. Is this the right formula? (100.00* SUM(a_n_difference)/ COUNT(a_n_difference)) and I have to group it by vague_generic_name.
I created a new column called something_percentage FLOAT() <<
Where is the code for this? Why did you use FLOAT?
I am using the statement
UPDATE Table vague_generic_name
SET something_percentage = (100*SUM(a_n_difference)/COUNT(a_n_difference))
GROUP BY vague_generic_name;
<<
NO! Think about how a GROUP BY works. I want you to edit this skeleton for data types, keys and give us valid ISO-11179 data element names.
CREATE TABLE Foobar
(vague_generic_name CHAR(10) NOT NULL,
PRIMARY KEY (??),
something_lower_limit ?? NOT NULL,
something_upper_limit ?? NOT NULL,
CHECK (something_lower_limit <= something_upper_limit),
a_value ?? NOT NULL
n_value ?? NOT NULL);
Then give us some sample data and expected results. This is easy to put into a VIEW and not keep doing punch card programs in SQL. But you have to follow minimal Netiquette if you really want help.