怀疑SQL查询 [英] Doubt in a sql query
问题描述
PLANTATION_TYPE AREA_ACRES 品种
Plant 5 Master
植物7糖
响尾蛇5大师
响尾蛇8私人
我有这种格式的表格.我需要一个SQL查询,该查询应该以以下格式给出结果:
品种 种植英亩 Ratoon_Acres Totat_Acres
硕士5 5 10
对于每个品种",我都应该获取Plant和Ratoon(Plantation_Types)的详细信息,然后将它们的总和作为Total_Acres.
能否请您告诉我该怎么做,
adv
Hi,
PLANTATION_TYPE AREA_ACRES VARIETY
Plant 5 Master
Plant 7 Sugar
Ratoon 5 Master
Ratoon 8 Private
I have table in this format.I need a sql query that should give me the result in the format as
VARIETY Plant_Acres Ratoon_Acres Totat_Acres
Master 5 5 10
for every ''variety'' i should get the details of Plant and Ratoon(Plantation_Types) then their sum as Total_Acres.
Could some please tell me how to do this,
Tnx in adv
推荐答案
使用GroupBy子句
就像
Use GroupBy Clause
like
select sum(Price),Category_Id from YourTable group by (Category_Id)
您可以使用crossTab查询.
访问此链接.
http://www .simple-talk.com/sql/t-sql-programming/creating-cross-tab-queries-and-pivot-tables-in-sql/ [ http://msdn.microsoft.com/en-us/library/ms177410.aspx [ ^ ]
在SQL Server 2005中透视两个或更多列 [在SQL中使用数据透视表进行报告 [在sql server2005中使用透视图的动态存储过程 [ ^ ]
you can use crossTab query.
visit this links.
http://www.simple-talk.com/sql/t-sql-programming/creating-cross-tab-queries-and-pivot-tables-in-sql/[^]
http://msdn.microsoft.com/en-us/library/ms177410.aspx[^]
Pivot two or more columns in SQL Server 2005[^]
Using Pivot In SQL for Reporting[^]
dynamic Stored procedure using pivot in sql server2005[^]
这篇关于怀疑SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!