求数据统计语句 select right(域名,len(域名)-charindex('@',域名)), count(*),sum(数量) from tb1group by right(域名,len(域名)-charindex('@',域名)) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select right(emai,len(emai)-charindex('@',emai))域名,count(*)数量 from tb1 group by right(emai,len(emai)-charindex('@',emai)) select substring(email,charindex('@',email),len(email)) as 域名, count(1) as 数量from tb1group by substring(email,charindex('@',email),len(email)) ---测试数据---if object_id('[tb1]') is not null drop table [tb1]gocreate table [tb1]([email] varchar(17))insert [tb1]select '[email protected]' union allselect '[email protected]' union allselect '[email protected]' union allselect '[email protected]' union allselect '[email protected]' union allselect '[email protected]' union allselect '[email protected]' union allselect '[email protected]' union allselect '[email protected]' ---查询---select substring(email,charindex('@',email),len(email)) as 域名, count(1) as 数量from tb1group by substring(email,charindex('@',email),len(email))---结果---域名 数量 ----------------- ----------- @126.com 3@21cn.com 1@hotmail.com 1@sina.com 2@sohu.com 1@yahoo.com.cn 1(所影响的行数为 6 行) 我用这个查询出来了结果,但是有一问题,出现重复的域名,如下:1.163.com126.comsina.comqq.comhotmail.comyahoo.com.cnsohu.com21cn.comtom.com2.163.com yahoo.comgmail.comeyou.comsina.com.cnmsn.com263.netsina.com 第二个163.com域名比第一域163.com的域名多了个空格。我在数据里也没有查询到有空格我也用replace修改过了,但是就是修改不过来。但是一统计还是会出现重复的域名。 用len和unicode函数看看两个有什么不一样的比如select unicode('163')返回的是13,你可以看看所谓的空格是什么字符然后用函数char(编码)来replace掉 求 简单sql 查询 两个中不同的日期 Sqlserver中的表更新不了 【100分_菜鸟提问】兄弟们,帮忙看看这两段代码,关于数据调用 SQL2000 用SQL语句插入标识列.(表中没有标识列) 谁能解释下下面6个数据库名词之间的关系和联系: 报料:关于CAST(DECIMAL(9,2) AS BINARY(8))的转换方式。 怎么暂停事务 大容量数据存储? 还是字段拆分问题? 从internet数据服务器上到本地数据库的数据更新 继续提问呀,求教!!! 求一条查询语句
from tb1 group by right(emai,len(emai)-charindex('@',emai))
substring(email,charindex('@',email),len(email)) as 域名,
count(1) as 数量
from tb1
group by substring(email,charindex('@',email),len(email))
if object_id('[tb1]') is not null drop table [tb1]
go
create table [tb1]([email] varchar(17))
insert [tb1]
select '[email protected]' union all
select '[email protected]' union all
select '[email protected]' union all
select '[email protected]' union all
select '[email protected]' union all
select '[email protected]' union all
select '[email protected]' union all
select '[email protected]' union all
select '[email protected]'
---查询---
select
substring(email,charindex('@',email),len(email)) as 域名,
count(1) as 数量
from tb1
group by substring(email,charindex('@',email),len(email))
---结果---
域名 数量
----------------- -----------
@126.com 3
@21cn.com 1
@hotmail.com 1
@sina.com 2
@sohu.com 1
@yahoo.com.cn 1(所影响的行数为 6 行)
126.com
sina.com
qq.com
hotmail.com
yahoo.com.cn
sohu.com
21cn.com
tom.com
2.163.com
yahoo.com
gmail.com
eyou.com
sina.com.cn
msn.com
263.net
sina.com 第二个163.com域名比第一域163.com的域名多了个空格。
我在数据里也没有查询到有空格
我也用replace修改过了,但是就是修改不过来。但是一统计还是会出现重复的域名。
163')返回的是13,你可以看看所谓的空格是什么字符然后用函数char(编码)来replace掉