In: Computer Science
Does the data contain errors? If so, write queries in SQL to find these errors and propose a way to address the issues
Theres a change of weight error (end weight-start weight) calculated wrong
and a logical error
Yes, Of Course the data contain the errors. I think the errors may be:
To Fix this issue using sql queries: create a measure using ALL() function to calculate the max value, ALL() function ignores all slicers and visual/page/report filters.
To Fix this issue using sql queries: By default, SQLite does not display NULL values in its output. The .nullvalue command causes SQLite to display the value you specify for NULLs. We will use the value -null- to make the NULLs easier to see
SELECT * FROM Visited;
SELECT * FROM Visited WHERE dated IS NULL;
To Fix this issue using sql queries: The correlated subquery causes the ERROR: because it has multiple rows:
, CASE
WHEN a.Group IN (' ')
THEN (select first(b.group) from mydata as b where first(a.Group_no) = first(b.Group_no))
END AS group_desc2
Change the sub-query to one that returns a single row. Something like:
, case
when not missing(group) then group
else (select min(group) from have as inner where inner.group_no = outer.group_no)
end
as group
Fix weight error which was calculated wrong:
For Example..Weight Decimal (5,2) means the total number of digits cannot exceed 5 and 2 digits can be placed to the right of the decimal. However, the value 1000.45 in the second line of code above exceeds the specified range of (5, 2) since it means 6 digits in total and throws an overflow error .
Fix using
ALTER TABLE Table_name ALTER COLUMN Weight decimal (6,2)
About logical error :
Sometimes, a subcondition is inconsistent, but the entire condition is consistent (e.g., because of a disjunction). Of course, also the opposite can happen: Sub Conditions that are tautologies.Both kinds of unnecessary complications indicate logical misconceptions and it is quite likely that the query will not behave as expected.Furthermore, implied sub conditions are unnecessary complications. In certain circumstances,implied sub conditions can help the optimizer to find a better execution plan, but then they should be clearly marked as an optimizer hint. In exams, it happens quite often that students adda condition, such as “A IS NOT NULL '' that is already enforced as a constraint.There are different possible formalizations of the requirement for “no unnecessary logicalcomplications”. A quite strict version is that whenever in the DNF of the query condition, asub condition is replaced by “true” or “false”, the result is not equivalent to the original condition.