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列表会出现乱码的情况,需要开启服务器呈现模式,如图: 特此记录一下
随机推荐
- node-mysql中的连接池代码学习
node-mysql是一个node.js下的mysql驱动,前段时间在处理连接池的问题上遇到了连接不释放的疑难杂症,虽已解决,但仍需总结经验避免下次重蹈覆辙.下面是node-mysql中的连接池的部分 ...
- Java 容器相关知识全面总结
Java实用类库提供了一套相当完整的容器来帮助我们解决很多具体问题.因为我本身是一名Android开发者,包括我在内很多安卓开发,最拿手的就是ListView(RecycleView)+BaseAda ...
- Nginx的配置文件(nginx.conf)解析和领读官网
步骤一:vi nginx.conf配置文件,参考本博文的最下面总结,自行去设置 最后nginx.conf内容为 步骤二:每次修改了nginx.conf配置文件后,都要reload下. index.ht ...
- 【转】并发编程之GCD
http://blog.xcodev.com/blog/2013/11/04/gcd-intro/ Dispatch Queue Dispatch Queue是一个任务执行队列,可以让你异步或同步地执 ...
- POj3268 Silver Cow Party
http://poj.org/problem?id=3268 题目大意:求到x距离与从x返回和的最大值 从x点到各个点最短路好求,直接用Dijkstar,但从各个点到x点却不好求,只要把路向翻转过来也 ...
- <a href="javascript:void(0);" id='test' onclick="javascript:alert('即将上线,敬请期待!');"><em class="rmwd"></em>征稿平台</a>
<a href="javascript:void(0);" id='test' onclick="javascript:alert('即将上线,敬请期待!');&q ...
- 用ConfigurationManager读取和修改配置文件
为了方便有时我们会把一些简单的配置的信息放入web.config文件里. 放到appSettings添加key value等信息. ConfigurationManager.AppSettings ...
- nrpe 在ubuntu上安装遇到的问题
Nagios Linux客户端需要安装NRPE进行数据收集,如果在Ubuntu系统下安装过程中遇到下面的错误提示:checking for SSL libraries... configure: er ...
- 解决mysql导入导出数据乱码问题
最近在linux上面用mysqldump导出数据,放在windows系统中导入就会出现中文乱码,然后就会导致出现: Unknown MySQL server host和Can't connect to ...
- 一次线上OOM故障排查经过
转贴:http://my.oschina.net/flashsword/blog/205266 本文是一次线上OOM故障排查的经过,内容比较基础但是真实,主要是记录一下,没有OOM排查经验的同学也可以 ...