sql - Why must you GROUP BY the columns in a CASE statement? -


I am trying to run a query against a table in SQL Server 2008 where some data was entered incompatible And I have it. To handle this,

table data example:

  OrderID Volume Value MarkedUpTotal 1 10 1,00 11,00 1 -1 1,00 -1,10 1 - 1 1,00 1,10  

I have to handle the situation where the quantity is negative but the marked yoga is recorded as positive.

I would like to run the following question:

  choose order-id, as SM order quantity, SM (quantity * value) as internalcost , In case when the volume is & lt; 0 more marked abdominal & gt; 0 So, in the form of ClientCost (-1 * MarkedUpTotal) and Yoga (MarkedUpTotal) from the OrderID by the OrderItems Group  

However, I get the following error when I run this query:

Invalid column selection in the list because it is not contained in either a composite function or GROUP BY clause.

Select the list that is invalid in the Column MarkedUpTotal because it is not contained in either a composite function or GROUP BY clause

I Desire the following results:

  OrderID OrderTotalQty InternalCost ClientCost 1 8 8.00 8.80  

It seems strange to me that I should be group by volume and mark up incomplete, when they only If I remove the last selection (Case Statement) if the CASE statement is conditionally used, then the query runs properly and there is no need for quantity or value in Group BY.

Why is SQL required? Is there a question that can fulfill the above?

Currently I am resolving this problem using a template table, if necessary, modify the MarkedUpTotal of each entry and then do a simple sum (MarkedUpTotal) in the main query from the temporary table Are there.

"itemprop =" text ">
  OrderTotalQty, the amount of orderID, SUM (quantity) selection of InternalCost, zodiac In the form (quantity * price) (case is when the & lt; 0 and MarkedUpTotal & gt; 0-1 * MarkedUpTotal or MarkedUpTotal) as the ClientCost order order IDs by the Order Group  

Because this gives error, because you are summoning it in the case - which will return out of 1 value. For the selection by the group, it will appear that you are having a numerical value (which can be fixed or from another source) in the form of columns.

Think about your SQL statement.

  SELECT OrderAid, in the form of SM (quantity) orderToolquity, in the case of SM (quantity * value), in the case of internalcost Quantity and lt; 0 more marked abdominal & gt; ClientCost from OrderItems Group, from 0 to 10 ELSE 20 END, from OrderIt  

is now returning a new column (ClientCost), which is not using any aggregation.
So it asks you to use it in Expression by GROUP.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -