【简单问题】如何得到一个数据表中某字段重复次数最多的记录
例如某表
Name FuckDate MMName FuckPlace
-----------------------------------
LZ 2007-03-08 Lily Home
LZ 2007-03-09 Lily Hotel
LZ 2007-03-15 Lisa Home
LZ 2007-03-20 Lily Car
LZ 2007-03-21 Lily Street
要求输入LZ,得到Lily
怎么实现呢?
[解决办法]
select top 1 MMName
from tablename
where name = 'LZ '
group by MMName
order by count(1) desc
[解决办法]
select top 1 MMName from 表
where NAME= 'LZ '
group by MMName ordey by count(MMName) desc
[解决办法]
[解决办法]
晕,楼上的仔细
我还没看出来呢
[解决办法]
果然是
[解决办法]
Name FuckDate MMName FuckPlace
-----------------------------------
LZ 2007-03-08 Lily Home
LZ 2007-03-09 Lily Hotel
LZ 2007-03-15 Lisa Home
LZ 2007-03-20 Lily Car
LZ 2007-03-21 Lily Street
------------------
弓虽!
[解决办法]
作 者: chieftech (纯真处男,欢迎诱奸(QJ太疼))
[解决办法]
查询的结果是最佳女主角?三八红旗手?
[解决办法]
select top 1 'LZ like '+mmname+ ' best.often in '+fuckplace from 表
where name= 'lz '
group by all mmname,fuckplace
order by count(*) desc
楼主猜结果是什么?
[解决办法]
to:gahade,凡事就怕认真……
--创建测试环境
create table 表(Name varchar(10),FuckDate datetime,MMName varchar(10),FuckPlace varchar(10))
--插入测试数据
insert 表(Name,FuckDate,MMName,FuckPlace)
select 'LZ ', '2007-03-08 ', 'Lily ', 'Home ' union all
select 'LZ ', '2007-03-09 ', 'Lily ', 'Hotel ' union all
select 'LZ ', '2007-03-15 ', 'Lisa ', 'Home ' union all
select 'LZ ', '2007-03-20 ', 'Lily ', 'Car ' union all
select 'LZ ', '2007-03-21 ', 'Lily ', 'Street '
--求解过程
select top 1 'LZ like '+mmname+ ' best.often in '+fuckplace from 表
where name= 'lz '
group by all mmname,fuckplace
order by count(*) desc
--删除测试环境
drop table 表
/*--测试结果
-------------------------------------------
LZ like Lily best.often in Home
(所影响的行数为 1 行)
*/