如何在GridView中显示价格总计 [英] how to display total of price in gridview

查看:65
本文介绍了如何在GridView中显示价格总计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SQL编程的新手.需要您的建议.
这是我的要求:



以下是我的示例数据

创建表测试(TransactionDate DateTime,价格INT,无INT)
我在表格Test
中插入一些如下所示的值 ------------------------------------
TransactionDate价格编号
------------------------------------
2007-01-21 16:01:00.000 61 23
2007-01-12 07:03:00.000 94 31
2007-01-24 00:13:00.000 71 26
2007-02-08 02:43:00.000 89 27
2007-02-09 20:41:00.000 53 21
2007-02-09 18:43:00.000 58 32
2007-02-22 11:00:00.000 81 19
2007-02-14 07:39:00.000 50 25
2007-03-15 00:17:00.000 45 23
2007-03-03 22:07:00.000 41 18
2007-03-15 09:17:00.000 85 30
2007-03-07 15:51:00.000 34 13
2007-03-07 21:05:00.000 53 18

出于上述原因,我希望得到如下select语句的结果

成绩取决于某些范围和
-----------------------------------------
GroupwiseMonth Groupwise总成绩
-----------------------------------------
1月63日A
2月55日c
3月61日B
-----------------------------------------
合计:179
-----------------------------------------

我想在GridView中这样显示,所以请帮助我,先生.....

并向我发送一些最佳的DateTime函数链接以进行练习....

I am new to Programming in SQL. Need your suggestions.
Here is my requirement:



Below is my sample data

CREATE TABLE Test(TransactionDate DateTime, price INT, no INT)
I insert some values like below into the table Test
------------------------------------
TransactionDate Price no
------------------------------------
2007-01-21 16:01:00.000 61 23
2007-01-12 07:03:00.000 94 31
2007-01-24 00:13:00.000 71 26
2007-02-08 02:43:00.000 89 27
2007-02-09 20:41:00.000 53 21
2007-02-09 18:43:00.000 58 32
2007-02-22 11:00:00.000 81 19
2007-02-14 07:39:00.000 50 25
2007-03-15 00:17:00.000 45 23
2007-03-03 22:07:00.000 41 18
2007-03-15 09:17:00.000 85 30
2007-03-07 15:51:00.000 34 13
2007-03-07 21:05:00.000 53 18

Out of the above I would want to have the result of a select statement as below

grade depends on some ranges and
-----------------------------------------
GroupwiseMonth GroupwiseTotal Grade
-----------------------------------------
Jan 63 A
Feb 55 c
Mar 61 B
-----------------------------------------
Total : 179
-----------------------------------------

I want to display like this in GridView so please help me sir.....

and send me some of best DateTime functions links for practice....

推荐答案

要按月分组,您可以使用
To group by the month yu can use DATEPART[^]. For example:
SELECT DATEPART(month, TransactionDate), SUM(price)...
FROM Test
GROUP BY  DATEPART(month, TransactionDate)



根据年级的逻辑,您可能必须更改查询的结构.



Depending on the logic of the grade you may have to change the structure of the query.


请尝试以下查询:

我在sql中没有任何表,请检查一下.如果无法解决,请在我这边尝试.
try below query:

I don''t have any table in sql, pls check it. if not solve then try at my side.
Select CONVERT(CHAR(4), TransactionDate, 100), SUM(Price) from Test group by CONVERT(CHAR(4), TransactionDate, 100)


这篇关于如何在GridView中显示价格总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆