镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 1 base code use master drop database helloworld --创建一个数据库 create database helloworld --用helloworld1这个数据库 use helloworld --创建一个表格teacher create table
得到一张表里按u_id分组,按count(id)排序,每个分组的pub_time最大的哪些记录,只取count(id)最大的4条 select a.u_id,a.name,a.u_name,a.id,a.pub_time,b.cn from mb_resource a,(select max(pub_time) as pub_time,u_id,count(id) AS cn from mb_resource where auth_status = 2 GROUP BY u_id) b wher
List<LeaderKaoQin> lstLeader = new List<LeaderKaoQin>();//一个List集合IGrouping<string, LeaderKaoQin> IGroups = null;//由于 group 查询产生的 IGrouping<TKey,?TElement> 对象实质上是列表的列表,所以需遍历2次List<IGrouping<string, LeaderKaoQin>> dep
先来看看 linq的,下面的一段linq 是 ,在 学生导入数据的时候,我们根据学生的手机号码和学生名称进行分组,如果有重复的,我们就筛选出来,用到了 linq的 group by,注意这里是new出来 2个条件来进行分组,分别是telephone和studentname 这2个组成分组的条件,并且是判断分组后是否有重复 (count>1),如果有重复,就添加到 stugroup这个变量里面. 再最后,我们用 foreach进行循环输出 var studentQuery = from stu i
文章参考http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/ 首先建表: SET FOREIGN_KEY_CHECKS=0; -- ------------------------------ Table structure for `fruit`-- ----------------------------DROP TABLE IF EXISTS `fruit`;CR