我有多表的这个视图

ACCOUNT_NAME .......奖金..........值

customer1表............一............ 14000

customer1表............乙............ 500

customer1表............Ç............ 14500

............的customer2一............ 20000

的customer2 ............乙............ 200

的customer2 ............Ç............ 20200

http://im33.gulfup.com/Nt0mM.png

我如何检索此视图并使用LINQ在GridView上显示此视图

...................甲.........乙..........Ç

customer1表....... 14000 ....... 500 ....... 14500

的customer2 ....... 20000 ....... 200 ....... 20200

在此输入图像描述

===============>>#1 票数:1 已采纳

SELECT account_name, 
SUM(CASE WHEN bonus = 'A' THEN value ELSE 0 END) AS A,
SUM(CASE WHEN bonus = 'B' THEN value ELSE 0 END) AS B,
SUM(CASE WHEN bonus = 'C' THEN value ELSE 0 END) AS C
FROM YouView
GROUP BY account_name

===============>>#2 票数:1

我解决了我的问题使用Pivots动态为realnumber3012推荐...

表格的演示和此链接的结果

在此输入图像描述


DECLARE @cols NVARCHAR(2000)
SELECT  @cols = COALESCE(@cols + ',[' + bounse_name+ ']','[' + bounse_name + ']')
FROM    dbo.tbl_bounse
DECLARE @query NVARCHAR(4000)
SET @query = N'SELECT account_name , '+ @cols +'
FROM
(SELECT     tbl_account.account_name, tbl_account.account_career,     
            tbl_bounse.bounse_name, tbl_detail.detail_value
FROM         tbl_account INNER JOIN
tbl_detail ON tbl_account.account_id = tbl_detail.detail_accound_id 
INNER JOIN
tbl_bounse ON tbl_detail.detail_bounce_id = tbl_bounse.bounse_id                     
                   )  p
PIVOT
(
MAX([detail_value])
FOR bounse_name IN
( '+
@cols +' )
) AS pvt;'

EXECUTE(@query)

  ask by Fadi translate from so

未解决问题?本站智能推荐: