Sql Query用于组合不同的行 [英] Sql Query for combining different rows
本文介绍了Sql Query用于组合不同的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
Hi All,
email id transaction year Net amount($) Count of transaction
--------- ---------------- ------------ -------------------
ab@xy.com 2008 32
ab@xy.com 2008 20
ab@xy.com 2008 565
ab@xy.com 2009 55
ab@xy.com 2010 88
ab@xy.com 2010 45
ab@xy.com 2009 5
cd@cv.com 2005 8
cd@cv.com 2005 5
cd@cv.com 2011 65
cd@cv.com 2011 665
cd@cv.com 2011 56
cd@cv.com 2011 8
考虑这张表。我需要以下面的格式将结果作为电子邮件ID,交易年份,净额和特定年份的交易。
例如:
Consider this table. I need the result as email id, transaction year, net amount and no of transaction in particular year in the below format.
For eg:
ab@xy.com 2008 617 3
ab@xy.com 2009 55 1
ab@xy.com 2010 133 2 etc...
如何在SQL服务器中编写查询?请帮忙。
问候,
Shanif
How can I write query in SQL server? Please help.
Regards,
Shanif
推荐答案
)伯爵交易
--------- ---------------- ------------ -------- -----------
ab@xy.com 2008 32
ab@xy.com 2008 20
ab@xy.com 2008 565
ab @ xy.com 2009 55
ab@xy.com 2010 88
ab@xy.com 2010 45
ab@xy.com 2009 5
cd@cv.com 2005 8
cd@cv.com 2005 5
cd@cv.com 2011 65
cd@cv.com 2011 665
cd@cv.com 2011 56
cd @ cv .com 2011 8
) Count of transaction --------- ---------------- ------------ ------------------- ab@xy.com 2008 32 ab@xy.com 2008 20 ab@xy.com 2008 565 ab@xy.com 2009 55 ab@xy.com 2010 88 ab@xy.com 2010 45 ab@xy.com 2009 5 cd@cv.com 2005 8 cd@cv.com 2005 5 cd@cv.com 2011 65 cd@cv.com 2011 665 cd@cv.com 2011 56 cd@cv.com 2011 8
考虑此表。我需要以下面的格式将结果作为电子邮件ID,交易年份,净额和特定年份的交易。
例如:
Consider this table. I need the result as email id, transaction year, net amount and no of transaction in particular year in the below format.
For eg:
ab@xy.com 2008 617 3
ab@xy.com 2009 55 1
ab@xy.com 2010 133 2 etc...
如何在SQL服务器中编写查询?请帮忙。
问候,
Shanif
How can I write query in SQL server? Please help.
Regards,
Shanif
尝试:
SELECT emailid, transyear, sum(transvalue), count(transvalue) FROM myTable GROUP BY emailID, transyear
这篇关于Sql Query用于组合不同的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文