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列表会出现乱码的情况,需要开启服务器呈现模式,如图: 特此记录一下
随机推荐
- Spring学习笔记(一) Spring基础IOC、AOP
1. 注入类型 a) Spring_0300_IOC_Injection_Type b) setter(重要) c) 构造方法(可以忘记) d) ...
- PyBayes的安装和使用
PyBayes 主页 文档 PyBayes is an object-oriented Python library for recursive Bayesian estimation (Bayesi ...
- J2EE开发常用开源框架技术(转)
1持久层:1)Hibernate这个不用介绍了,用的很频繁,用的比较多的是映射,包括继承映射和父子表映射对 于DAO在这里介绍个在它基础上开发的包bba96,目前最新版本是bba96 2.0它对Hib ...
- Myeclipse 快捷键设置和自动提示设置
1.快捷键设置和调整 2.自动提示信息设置与调整
- linux下编译lua
curl -R -O http://www.lua.org/ftp/lua-5.2.3.tar.gz 编译代码时,遇到如下错误 /usr/lib/libreadline.so: undefined r ...
- Android实例-读取设备联系人(XE8+小米2)
相关资料: http://www.colabug.com/thread-1071065-1-1.html 结果: 1.将权限打开Read contacts设置为True,不然报图一的错误. 2.搜索空 ...
- Rop 文件上传解决思路
由于服务请求报文是一个文本,无法直接传送二进制的文件内容,因此必须采用某种转换机制将二进制的文件内容转换为字符串.Rop 采用如下的方式对上传文件进行编码:<fileType>@<B ...
- SASS优化响应式断点管理
前端开发whqet,csdn,王海庆,whqet,前端开发专家 原文:<Managing Responsive Breakpoints with Sass> 作者:Hugo Giraude ...
- Java网页数据采集器[续篇-远程操作]【转载】
本期概述 上期我们学习了html页面采集后的数据查询, 但这仅仅是在本地查询数据库,如果我们想通过远程操作来进行数据的采集,存储和查询,那又该怎么做呢? 今天我们一起来学习下:如何通过本地客户端远程访 ...
- Codeforces Round #280 (Div. 2) E. Vanya and Field 数学
E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...