我有一个从SQL语句派生的gridview。我现在想要显示每列的小计,然后显示2个日期范围之间的总增加/减少百分比。我该怎么做呢?
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Sales-Comparison.aspx.cs" Inherits="TowelsRusV3.Sales_Comparison" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="panel panel-info">
<div class="panel-heading">
<h1 class="panel-title text-center">Sales Comparison</h1>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-8">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CssClass="table table-bordered table-responsive table-striped" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" ShowFooter="True">
<Columns>
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate" ReadOnly="True" SortExpression="OrderDate" />
<asp:BoundField DataField="Total2014" HeaderText="Total2014" ReadOnly="True" SortExpression="Total2014" />
<asp:BoundField DataField="Total2013" HeaderText="Total2013" ReadOnly="True" SortExpression="Total2013" />
<asp:BoundField DataField="Difference" HeaderText="Difference" ReadOnly="True" SortExpression="Difference" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LiveDataV2ConnectionString %>" SelectCommand="SELECT
Table2014.OrderDate,
isnull(Table2014.Total,0) as Total2014,
isnull(Table2013.Total,0) as Total2013,
isnull(Table2014.Total,0)-isnull(Table2013.Total,0) as Difference
FROM
(SELECT SUM(order_header_total.oht_net) AS Total,
dateadd(day,0,DATEDIFF(d,0,order_header.oh_datetime)) as OrderDate
FROM order_header_total
INNER JOIN order_header ON order_header_total.oht_oh_id = order_header.oh_id
WHERE (order_header.oh_datetime BETWEEN '12/01/2014' AND '12/31/2014')
AND order_header.oh_os_id IN (1, 6, 4)
GROUP BY dateadd(day,0,DATEDIFF(d,0,order_header.oh_datetime))) Table2014
LEFT OUTER JOIN
(SELECT SUM(order_header_total.oht_net) AS Total,
dateadd(year,1,dateadd(day,0,DATEDIFF(d,0,order_header.oh_datetime))) as OrderDate
FROM order_header_total
INNER JOIN order_header ON order_header_total.oht_oh_id = order_header.oh_id
WHERE (order_header.oh_datetime BETWEEN dateadd(year,-1,'12/01/2014') AND dateadd(year,-1,'12/31/2014'))
AND order_header.oh_os_id IN (1, 6, 4)
GROUP BY dateadd(year,1,dateadd(day,0,DATEDIFF(d,0,order_header.oh_datetime)))) as Table2013 On Table2013.OrderDate = Table2014.OrderDate
order by Table2014.OrderDate"></asp:SqlDataSource>
</div>
</div>
</div>
</div>
</asp:Content>
答案 0 :(得分:0)
您应该能够在select语句的末尾添加一个类似于
的新列sum(table_a.col1) + sum(table_b.coly) as SubTotal
然后就你的百分比列做同样的事情,只想弄清楚如何计算百分比。