记录一下,方便自己以后查看,以后会随时添加
1,查询重复数据
select project_id,house_location,count(*) from house_price group by house_location having count(house_location)>1;
2,删除重复的数据,并保留一条
DELETE FROM house_price WHERE id IN (SELECT ub.rowid FROM ( SELECT min(id) rowid FROM house_price t2 WHERE t2.project_id = 1358 GROUP BY t2.house_location ) ub)
3,对字符串排序问题,我的数据里有一列是字符串类型的数字和字母和/的混合数据。我仍然想按照数字的大小,由小到大排序
SELECT *,(unit_no+0 > 0) boolNum FROM house_price WHERE project_id = 1400 GROUP BY unit_no
ORDER BY boolNum DESC, (unit_no+0) ASC, unit_no;结果如下:
4,对null的排序。
null值排在最后,用Mysql的IF和ISNULL函数。如果为空返回1,否返回0
select * from A order by IF(ISNULL(a),1,0),a desc
null值排在最前,用Mysql的IF和ISNULL函数。如果为空返回1,否返回0
select * from A order by IF(ISNULL(a),0,1),a desc