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列表会出现乱码的情况,需要开启服务器呈现模式,如图: 特此记录一下
随机推荐
- TCPSocket v1.0 for cocos2d-x下载
下载地址:http://files.cnblogs.com/elephant-x/TCPSocketLibs_V1.0.rar 这是自己封装的一个TCPSOCKET包,是独立于cocos2d-x的,使 ...
- uva10474 简单排序查找 一次AC
题目很简单,加上读题20分钟一次AC.还是用到了快排qsort. #include<iostream> #include<cstdlib> using namespace st ...
- Unity3D细节整理:AssetBundle对应的各种格式文件的类型
我们打包AssetBundle后,Unity3D会根据文件的后缀名将文件转换为特定的类型对象存储起来,我们后期获取时需要根据这些类型取出打包的数据,这里记录下不同后缀文件打包后的类型. 文本格式 支持 ...
- MVC神韵---你想在哪解脱!(十五)
在模型中添加验证规则 本节介绍如何在我们的Movie(电影)模型中添加一些验证规则,同时确认当用户使用我们的应用程序创建或编辑电影信息时将使用这些验证规则对用户输入的信息进行检查.首先,让我们在Mov ...
- presentedViewController 和 presentingViewController 以及 dismissViewControllerAnimated 的使用
在日常的开发中,多控制器之间的跳转除了使用push的方式,还可以使用 present的方式,present控制器时,就避免不了使用 presentedViewController.presenting ...
- 剑指OFFER之旋转数组的最小数字(九度OJ1386)
题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转 ...
- Android内存优化(使用SparseArray和ArrayMap代替HashMap)
在Android开发时,我们使用的大部分都是Java的api,比如HashMap这个api,使用率非常高,但是对于Android这种对内存非常敏感的移动平台,很多时候使用一些java的api并不能达到 ...
- ie6的兼容问题及解决方案
1.png24位的图片在ie6浏览器上会出现背景,解决方案是做成png8位: 2.浏览器默认的margin和padding不同,解决方法是用全局重置来统一,即是*{margin:0;padding:0 ...
- HTML输出 二 控制行背景颜色
$Infors = Get-Content ports01.txt$Temp_PortStatustxt = "C:\Windows\Temp\PortStatustxt.txt" ...
- hdu 5427 A problem of sorting 水题
A problem of sorting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contest ...