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列表会出现乱码的情况,需要开启服务器呈现模式,如图: 特此记录一下
随机推荐
- AHOI2013 Round2 Day1 简要题解
第一题,好吧这是个dp.(搜素也能在BZOJ上卡过). 第二题,BFS搜索碰到的立方体面数,智硬没有想到... 第三题,其实一看就有思路,但关键是求x坐标不交的矩形对数+y坐标不交的矩形对数 - x, ...
- HTTPS 升级指南
上一篇文章我介绍了 HTTP/2 协议 ,它只有在 HTTPS 环境才会生效. 为了升级到 HTTP/2 协议,必须先启用 HTTPS.如果你不了解 HTTPS 协议(学名 TLS 协议),可以参考我 ...
- HDU 5680 zxa and set (数学 推导结论)
zxa and set 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/G Description zxa has a set , ...
- JSF 2 password example
In JSF, you can use the <h:inputSecret /> tag to render a HTML input of type="password&qu ...
- Codeforces 600B Queries about less or equal elements(二分查找)
Description You are given two arrays of integers a and b. For each element of the second array bj yo ...
- flask中的request.form对象方法
'add','clear','copy','deepcopy','fromkeys','get','gtlist','has_key','items','iteritems','iterkeys',' ...
- UVa 817 According to Bartjens (暴力,DFS)
题意:给出一个数字组成的字符串,然后在字符串内添加三种运算符号 * + - ,要求输出所有添加运算符并运算后结果等于2000的式子. 所有数字不能有前导0, 且式子必须是合法的. 析:这个题很明显的暴 ...
- poj3041
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12162 Accepted: 6620 Descri ...
- CodeForces 732C Sanatorium (if-else)
题意:某人去旅游,记录了一共吃了多少顿饭,早中晚,但是有可能缺少,问你最少缺少了多少顿. 析:每把三个数排序,然后再一一对比,肯定是以最大数为主,其他两个肯定是缺少了. 代码如下: #pragma c ...
- 糟糕的双重检查加锁(DCL)
在Java并发编程时,同步都会存在着巨大的性能开销,因此,人们使用了很多的技巧来降低同步的影响,这其中有一些技巧很好,但是也有一些技巧存在一些缺陷,下面要结束的双重检查加锁(DCL)就是有缺陷的一类. ...