CAML query for Group by count and data
CAML query for Group by count and data
| Company | Category | Product Name |
| Microsoft | Developer | Visual Studio |
| Microsoft | Consumer | Windows |
| Microsoft | Enterprise | SharePoint 2010 |
| Microsoft | Mobile | Windows 7 |
| Samsung | Consumer | Laptops |
| Samsung | Consumer | Mobiles |
| Samsung | Consumer | Tablet |
| Consumer | Search Engine | |
| Consumer | Google Maps |
The above is my SharePoint List, I want to group by company’s name and then count the number of rows for each grouped by data and also display only chunk of data that is grouped.
Company – Microsoft – 4 count
| Microsoft | Developer | Visual Studio |
| Microsoft | Consumer | Windows |
| Microsoft | Enterprise | SharePoint 2010 |
| Microsoft | Mobile | Windows 7 |
Company – Samsung – 3 count
| Samsung | Consumer | Laptops |
| Samsung | Consumer | Mobiles |
| Samsung | Consumer | Tablet |
Company – Google – 2 count
| Consumer | Search Engine | |
| Consumer | Google Maps |
My Solution – using CAML query LINQ
using (SPSite site = new SPSite(“http://server“))
{
SPWeb web = site.OpenWeb();
SPList listCAMLQuery = web.Lists["listName"];
SPQuery query = new SPQuery(); // query for all the items
DataTable dt = listCAMLQuery.GetItems(query).GetDataTable(); // get datatable for all the list items
if (dt != null && dt.Rows.Count > )
{
//Group the data
var groupedList = from row in dt.AsEnumerable()
group row by row.Field<string>(“Company”) into groupedTable
// Company is the column name for groupby
// string is the type of column
orderby groupedTable.Key // key is the groupby column category value
select new
{
Key = groupedTable.Key, // key is the groupby column category value
companyCount = groupedTable.Count(), // count for columns in a groupby
groupedRows = groupedTable.CopyToDataTable() // grouped data
};
// print result
foreach (var items in groupedList)
{
int count = items.companyCount; // count for columns in a groupby category
DataTable dt1 = items.groupedRows;
gv.DataSource = dt1; //gridview
gv.DataBind();
}
}
}
}
CAML query for Group by count and data的更多相关文章
- MongoDB学习笔记——聚合操作之group,distinct,count
单独的聚合命令(group,distinct,count) 单独聚合命令 比aggregate性能低,比Map-reduce灵活度低:但是可以节省几行javascript代码,后面那句话我自己加的,哈 ...
- 解决postgresql -- ERROR: 42601: query has no destination for result data
I am learning Npgsql and PostgreSQL. I am unable to define the output parameter correctly. What am I ...
- mysql查询出现In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'zhibo.a.id';
出现问题: Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In ...
- mysql5.7执行sql语句报错:In aggregated query without GROUP BY, expression #1 of SELECT list contains nonagg
mysql5.7执行sql语句报错:In aggregated query without GROUP BY, expression #1 of SELECT list contains nonagg ...
- Group By Count不能显示0的问题
问题: 如对表: /*==================================================== id |score |grade ------------------- ...
- SQL-7查找薪水涨幅超过15次的员工号emp_no以及其对应的涨幅次数t (group 与count)
题目描述 查找薪水涨幅超过15次的员工号emp_no以及其对应的涨幅次数tCREATE TABLE `salaries` (`emp_no` int(11) NOT NULL,`salary` int ...
- SharePoint CAML Query小结
CAML的结构. <View Type="HTML" Name="Summary"> <ViewBody ExpandXML="TR ...
- MySql 错误:In aggregated query without GROUP BY, expression #1 of SELECT list contains....
前段时间做sql注入的时候 使用group_concat时,出现标题上的错误.经查阅一位大佬的博客,成功解决!故写此博文! 当mysql的sql_mode是only_full_group_by的时候 ...
- SharePoint Caml Query 使用
需要注意的是: 再使用ListQueryWebPart部件时,默认查看的list列表会出现乱码的情况,需要开启服务器呈现模式,如图: 特此记录一下
随机推荐
- 无线 WIFI 的13个信道频率范围
目前主流的无线WIFI网络设备不管是802.11b/g还是802.11b/g/n 一般都支持13个信道.它们的中心频率虽然不同,但是因为都占据一定的频率范围,所以会有一些相互重叠的情况.下面是13个信 ...
- hive常见问题解决干货大全
本人,苦心多时,历经磨难和心血,与大家共同攻克问题难关! 问题一: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive ...
- homework-03
1.分工准备 这次的工作是结对编程,在第二次作业中我是使用python完成的作业,而小明是使用C完成的作业.因为打算使用动态链接库的方式将第二次的代码嵌入到本次的作业中,而python生成动态链接库不 ...
- UVALive 7281 Saint John Festival (凸包+O(logn)判断点在凸多边形内)
Saint John Festival 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/J Description Porto's ...
- HDU 4893 Wow! Such Sequence! (线段树)
Wow! Such Sequence! 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4893 Description Recently, Doge ...
- javascript中数组的迭代等操作
- POJ 1664 放苹果 (递推)
题目链接:http://poj.org/problem?id=1664 dp[i][j]表示i个盘放j个苹果的方案数,dp[i][j] 可以由 dp[i - 1][j] 和 dp[i][j - i] ...
- mybatis杂记
mybatis学习官网: 1.如果项目中使用maven管理,又引用 了mybatis框架, 下面是mybatis官网给出的 mybatis在maven中央仓库的坐标原文 详情见连接:https://c ...
- UI进阶 CocoaPods的安装使用步骤
一. CocoaPods简介 CocoaPods是一个用来帮助我们管理第三方依赖库的工具.在开发iOS应用时,会经常使用第三方类库,比如SDWebImage.AFNetworking等等,手动的下载与 ...
- C#学习笔记(十一):动态类型
C#是一门静态类型的语言,但是在C#4.0时微软引入了动态类型的概念. dynamic 关键字dynamic用来定义动态对象,我们来看一下动态类型的一些特性. 调用不同类的相同方法 我们有两个或多个不 ...