SQL如何Count Distinct过的数据
来源:互联网 发布:穆雅斓淘宝店铺号 编辑:程序博客网 时间:2024/05/20 00:39
distinct:
<pre name="code" class="sql">SELECT distinct t1.*,t2.industryId FROM positions t1 ,planteddetails t2, landplanted t3 where t3.landId = t1.id and t2.plantedId = t3.idand (t1.landType like '%粮%' or t1.gatherId like '%粮%') and t2.industryId ='1'
直接count会报错
SELECT count((distinct t1.*,t2.industryId FROM positions t1 ,planteddetails t2, landplanted t3) where t3.landId = t1.id and t2.plantedId = t3.idand (t1.landType like '%粮%' or t1.gatherId like '%粮%') and t2.industryId ='1'
所以我们可以换个思路
select count(*) from (SELECT distinct t1.*,t2.industryId FROM positions t1 ,planteddetails t2, landplanted t3 where t3.landId = t1.id and t2.plantedId = t3.idand (t1.landType like '%粮%' or t1.gatherId like '%粮%') and t2.industryId ='1') as total
直接把distinct的结果作为一张表count
这里as total是必须的 临时表需要名字 不然会报错
0 0
- SQL如何Count Distinct过的数据
- SQL 中 Count 和Distinct的使用
- count distinct是如何实现的
- SQL(select distinct count)
- SQL COUNT DISTINCT 函数
- SQL COUNT DISTINCT 函数
- SQL count distinct与NULL
- sql中count函数和distinct函数的配合使用
- 大数据下的Distinct Count(一):序
- 大数据下的Distinct Count(二):Bitmap篇
- SQL Server distinct top count 查询
- Hive SQL优化之 Count Distinct
- Hive SQL优化之 Count Distinct
- sql优化之:count(distinct xxxx)
- Hive SQL优化之 Count Distinct
- count(distinct)
- 一道看似简单的sql面试题(count,group by,distinct)
- VC++2005下的ADO SQL语句(like,count,distinct)和操作(转)
- AJAX 跨域请求 - JSONP获取JSON数据
- CodeBlock速配wxWidgets[U版]
- Spring 中注入bean的properties配置文件位置问题解决
- python 注意事项(—)
- html5入门之psd图解剖
- SQL如何Count Distinct过的数据
- 2016年1月 Android 开发技巧总汇
- Android 6.0: 动态权限管理的解决方案
- UVA442栈
- html文字超出隐藏并显示省略号
- Android Edittext监听
- 好的程序员的标杆在哪里?
- bat批处理删除指定N天前的文件
- OK6410-A开发板学习-⑤uboot移植(3)DM9000 网卡驱动移植