Quote (carteblanche @ Jun 25 2015 08:28pm)
you need to start giving simpler examples. get rid of all the joins and columns and conditions that aren't relevant to your actual question. then show a small sample of data (eg: 3 rows, 3 columns), and show me what you want the query to return. i'm not gonna strain to understand what c172424 is or follow all your float conversions or any of that other stuff
i stopped reading when it's clear you're not simplifying your examples.
without going into much details, i suggest you learn how to use subselects or unions.
eg use a single select to grab each piece of data you want, then union all the cases together.
or select the data difference as a virtual column integer, then do a select on top of it for your case statement to make it easier to follow.