引用: http://blog.sina.com.cn/s/blog_6c9d65a10101bkgk.htmlhttp://www.jb51.net/article/39302.htm 1.使用distinct去重(适合查询整张表的总数)有多个学校+教师投稿,需要统计出作者的总数 select count(author) as total from files 每个作者都投稿很多,这里有重复的记录. select distinct author from files; 有可能两个学校的教师姓名
1.列出当前db文件中所有的表的表名 SQL语句:SELECT * FROM sqlite_master WHERE type='table'; 结构如下: 注:网上有人说可以带上db文件的名称,如:SELECT * FROM dbname.sqlite_master WHERE type='table'; 但我试了不行...难道我姿势不对~ 2.判断某表是否存在SQL语句:select count(*) from sqlite_master where type='table' and nam
1 前言 项目中排行榜刚好需要查数据库表然后给出编号,方案一,可以按条件查找出来,然后再按数组序号给编号,但是如果要查表出来直接看,就不太够用了:方案二,就是用代码帮忙编号.参考了网上一些代码,然后发现方法都有一个样的,然后这边只是作为记录使用,方便查找. 2 代码 SELECT province_id, province_name, gdp, (@i :=@i + 1) AS No FROM province, (SELECT @i := 0) AS it ORDER BY gdp DESC
CREATE TABLE emp(id INT PRIMARY KEY,NAME VARCHAR(11),dep_id INT ,salary INT); CREATE TABLE dept(id INT PRIMARY KEY,NAME VARCHAR(11),parentid INT); 获取各部门人数信息: SELECT e.dep_id,d.name,COUNT(e.dep_id) FROM emp e,dept d WHERE e.dep_id=d.id GROUP BY e.dep_
select * from personal_question_answer where answer_id in ( select min(answer_id) from personal_question_answer where family_member_id='csaads16asadafds156aa' group by question_code ) ORDER BY question_code
1.查找表中多余的重复记录(多个字段) select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*)>1) 2.删除表中多余的重复记录(多个字段),只留有rowid最小的记录 delete from vitae a where (a.peopleId,a.seq) in (select peopleId,seq
一直找不出某个字段去重的前提下,还能够显示其它字段的数据 以下是解决方法: SELECT *, COUNT(DISTINCT( province)) FROM area_info WHERE type=1000 GROUP BY province 另一种方式 SELECT code,type FROM area_info WHERE type=1000 GROUP BY code,type
方法一:使用Set List<User> newList = new ArrayList<User>(); Set<String> set = new HashSet<String>(); for (User user : list) { String userName = user.getName(); if (!set.contains(userName)) { //set中不包含重复的 set.add(userName); newList.add(us
1.简单的,按月统计数量 SELECT CREATE_DATE, DATE_FORMAT(CREATE_DATE, '%Y-%m') AS month , COUNT(*) AS sum FROM pt_user GROUP BY month; 2.按月累加统计数据 SELECT a.month, SUM(b.total) AS total FROM ( SELECT DATE_FORMAT(CREATE_DATE, '%Y-%m') AS month, SUM(sum) AS total FR