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列表会出现乱码的情况,需要开启服务器呈现模式,如图: 特此记录一下
随机推荐
- How to interact with the Chef Server using the Chef Server API using Shell script
!/usr/bin/env bash _chef_dir () { # Helper function: # Recursive function that searches for chef c ...
- Row Border in DataGrid 表格边框
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 第三百零五天 how can I 坚持
今天去E世界拿抽的奖品,白去了 一趟,结果已经被拿过去了,明天还得去另一个地拿,太折腾了,今天走了1万4千多步. 哎,徐斌啊,出去见个面,这个折腾啊,受不了,想干他.开个玩笑. 黄东月,为什么打字莫名 ...
- linux下编译lua
curl -R -O http://www.lua.org/ftp/lua-5.2.3.tar.gz 编译代码时,遇到如下错误 /usr/lib/libreadline.so: undefined r ...
- STL学习系列六:List容器
List简介 list是一个双向链表容器,可高效地进行插入删除元素. list不可以随机存取元素,所以不支持at.(pos)函数与[]操作符.it++(ok), it+5(err) #include ...
- Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...
- mysql 报错之创建自定义函数
I experienced this error while trying to alter one of my stored procedures remotely on a master serv ...
- Oracle数据库如何授权收费(Database Licensing)
Oracle软件本身是免费的,所以任何人都可以从Oracle官方网站下载并安装Oracle的数据库软件,收费的是License,即软件授权,如果数据库用于商业用途,就需要购买相应Oracle产品的Li ...
- javascript操作Math对象的方法总结
//数学函数--abs 返回数字的绝对值 var a; /*a = Math.abs(-12); alert(a); //12 //数学函数--acos 返回数的反余弦数 a = Math.acos( ...
- 【HMTL】文字飞舞的美
这是在一个大神那看到的就拿过来了,希望能够更多人能看到. 这个是效果: 源文件下载: 点 击 下 载