首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

一个简单的有关问题没答上来,被鄙视了

2011-12-21 
一个简单的问题没答上来,被鄙视了表A是一个缓慢变化维度,记录了用户在不同时期所在的城市,现在需要把换过

一个简单的问题没答上来,被鄙视了
表A是一个缓慢变化维度,记录了用户在不同时期所在的城市,现在需要把换过城市的用户,城市列出,怎么实现。
ID       City   FromDate               ToDate
001     BJ       2003/03/01           2008/01/01
001     SH       2008/01/02          
002     BJ       2003/03/01           2008/01/01
002     BJ       2008/01/02          

结果
001   BJ
001   SH

[解决办法]
select id,city from 表A group by id,city having count(1)>1;
[解决办法]
select id,city from 表A group by id,city having count(1)>1;
[解决办法]
没有什么的,正常的,什么都精通的不叫人,叫神........

[解决办法]
上面有误,这个

SQL code
with temp as(  select '001' id, 'BJ' city from dual union all  select '001' id, 'SH' city from dual union all  select '002' id, 'BJ' city from dual union all  select '002' id, 'BJ' city from dual)SELECT id, city  FROM temp WHERE id IN (SELECT id FROM (SELECT DISTINCT id, city FROM temp) GROUP BY id HAVING COUNT(1) > 1);
[解决办法]
select id,city,row_number()over(parition by city order by id) row_num
from a
where row_num >1;
[解决办法]
探讨
上面有误,这个

SQL code
with temp as(
select '001' id, 'BJ' city from dual union all
select '001' id, 'SH' city from dual union all
select '002' id, 'BJ' city from dual union all
select '002'……

[解决办法]
SQL code
--5楼这个不对,改一下with temp as(  select '001' id, 'BJ' city from dual union all  select '001' id, 'SH' city from dual union all  select '002' id, 'BJ' city from dual union all  select '002' id, 'BJ' city from dual union all  select '003' id, 'BJ' city from dual)SELECT *  FROM temp a WHERE (SELECT COUNT(1)          FROM temp b         WHERE b.id = a.id AND               b.city <> a.city) > 0;
[解决办法]
我只是来接分的~!
[解决办法]
select id,city from 表A
 where id in (select id from 表A group by id,city having count(1)=1);

热点排行
Bad Request.