如果可以在Linq中执行某些操作,那么总是可以在SQL中执行这些操作吗?
我正在尝试编写一个SQL语句,它的功能应该与下面的Linq查询类似。主要是,我想根据某个条件(Type==“Check”)将一列(Value*Quantity)中的两列(现金和支票)相加。因此,如果类型为“Check”,则将该值放入Check列,否则将其放入Cash列 林克: SQL:如果可以在Linq中执行某些操作,那么总是可以在SQL中执行这些操作吗?,sql,linq,Sql,Linq,我正在尝试编写一个SQL语句,它的功能应该与下面的Linq查询类似。主要是,我想根据某个条件(Type==“Check”)将一列(Value*Quantity)中的两列(现金和支票)相加。因此,如果类型为“Check”,则将该值放入Check列,否则将其放入Cash列 林克: SQL: 这可能吗?您可以这样做: select sum(case when type = 'cash' then Value * Quantity else 0 end) as Cash, sum(case wh
这可能吗?您可以这样做:
select sum(case when type = 'cash' then Value * Quantity else 0 end) as Cash,
sum(case when type = 'check' then Value * Quantity else 0 end) as Check
from ...
如果这是MS SQL2005及以上版本,也可以使用PIVOT关键字
SELECT a.SessionIdentifier, a.Checks as CheckQuantity, ???? as Cash, ???? as Check
FROM Acquisitions ac
INNER JOIN AcquiredItems ai ON ai.AcquisitionIdentifier = ac.Identifier
GROUP BY a.SessionIdentifier
select sum(case when type = 'cash' then Value * Quantity else 0 end) as Cash,
sum(case when type = 'check' then Value * Quantity else 0 end) as Check
from ...