TSQL:A表字段与B表中的关联,关联条件中一列是随机关联的实现方式
A表字段与B表中的关联,关联条件中一列是随机关联的实现方式
create table test(
rsrp string,
rsrq string,
tkey string,
distan string
); insert into test values('-90.28','-37','tkey1','');
insert into test values('-92.35','-40','tkey1','');
insert into test values('-94.36','-34','tkey2','');
insert into test values('-93.88','-38','tkey2',''); select * from test;
+------------+------------+------------+--------------+--+
| test.rsrp | test.rsrq | test.tkey | test.distan |
+------------+------------+------------+--------------+--+
| -90.28 | -37 | tkey1 | 10 |
| -92.35 | -40 | tkey1 | 30 |
| -94.36 | -34 | tkey2 | 5 |
| -93.88 | -38 | tkey2 | 19 |
+------------+------------+------------+--------------+--+ create table test_latlng
(
tkey string,
lat string,
lng string
);
insert into test_latlng values('tkey1','lat1','lng1');
insert into test_latlng values('tkey1','lat2','lng2');
insert into test_latlng values('tkey1','lat3','lng3');
insert into test_latlng values('tkey1','lat4','lng4');
insert into test_latlng values('tkey2','lat1','lng1');
insert into test_latlng values('tkey2','lat2','lng2');
insert into test_latlng values('tkey2','lat3','lng3');
insert into test_latlng values('tkey2','lat4','lng4'); 0: jdbc:hive2://10.78.152.62:21066/> select * from test_latlng;
+-------------------+------------------+------------------+--+
| test_latlng.tkey | test_latlng.lat | test_latlng.lng |
+-------------------+------------------+------------------+--+
| tkey1 | lat1 | lng1 |
| tkey1 | lat2 | lng2 |
| tkey1 | lat3 | lng3 |
| tkey1 | lat4 | lng4 |
| tkey2 | lat1 | lng1 |
| tkey2 | lat2 | lng2 |
| tkey2 | lat3 | lng3 |
| tkey2 | lat4 | lng4 |
+-------------------+------------------+------------------+--+ select rsrp,rsrq,t10.tkey,lat,lng,t10.rn
from
(
select rsrp,rsrq,tkey,row_number()over(partition by tkey order by cast(rand() * 100 as int) asc) as rn
from test
group by rsrp,rsrq,tkey
) t10
inner join
(
select lat,lng,tkey,row_number()over(partition by tkey order by cast(rand() * 10000 as int) asc) as rn
from test_latlng
group by lat,lng,tkey
) t11
on t10.tkey=t11.tkey and t10.rn=t11.rn;
+---------+-------+-----------+-------+-------+---------+--+
| rsrp | rsrq | t10.tkey | lat | lng | t10.rn |
+---------+-------+-----------+-------+-------+---------+--+
| -90.28 | -37 | tkey1 | lat2 | lng2 | 1 |
| -92.35 | -40 | tkey1 | lat3 | lng3 | 2 |
| -93.88 | -38 | tkey2 | lat3 | lng3 | 1 |
| -94.36 | -34 | tkey2 | lat2 | lng2 | 2 |
+---------+-------+-----------+-------+-------+---------+--+
TSQL:A表字段与B表中的关联,关联条件中一列是随机关联的实现方式的更多相关文章
- oracle删除表字段和oracle表增加字段
这篇文章主要介绍了oracle表增加字段.删除表字段修改表字段的使用方法,大家参考使用吧 添加字段的语法:alter table tablename add (column datatype [d ...
- SQLserver触发器实现A表insert到B表
CREATE TABLE tab1(tab1_id varchar(11));CREATE TABLE tab2(tab2_id varchar(11)); 现在我们有两张表,要实现在A表里面inse ...
- mysql left join中where和on条件的区别
left join中关于where和on条件的几个知识点: 1.多表left join是会生成一张临时表,并返回给用户 2.where条件是针对最后生成的这张临时表进行过滤,过滤掉不符合where条件 ...
- mysql left join中on后加条件判断和where中加条件的区别
left join中关于where和on条件的几个知识点: .多表left join是会生成一张临时表,并返回给用户 .where条件是针对最后生成的这张临时表进行过滤,过滤掉不符合where条件的记 ...
- Mybatis中实体类中的字段跟对应表的字段不一致时解决办法
解决字段名与实体类属性名不相同的冲突 实体类字段: public class Order { private int id; private String orderNo; private float ...
- MySQL中 如何查询表名中包含某字段的表 ,查询MySql数据库架构信息:数据库,表,表字段
--查询tablename 数据库中 以"_copy" 结尾的表 select table_name from information_schema.tables where ta ...
- 在向"带有自增字段的数据库表"中插入数据时,自定义"该自增字段"的数据
在设计数据库表的时候,经常会使用自增主键或其他自增字段.比如: DB_UserGroups表中GroupID为该表主键,并为自增字段. 但在将某字段设置自增后,想在插入数据时,人为指定自增字段的数据内 ...
- Oracle中的自连接(self join)-当表中的某一个字段与这个表中另外字段的相关时,我们可能用到自连接。
http://blog.163.com/wkyuyang_001/blog/static/10802122820091751049479/ 当表中的某一个字段与这个表中另外字段的相关时,我们可能用到自 ...
- laravel 字段映射问题,表单中提交字段与数据表中字段不一致
在遇到提交表单时,表单中的name属性与数据表中的字段不一致,报错, 解决方法: 参考1:提交表单的时候,表单的name属性和数据表字段名称是一样的,这样有什么不妥么? 你数据库的信息给前端透露得越多 ...
随机推荐
- Batch update returned unexpected row count from update [0] 异常处理
在one-to-many时遇到此异常,本以为是配置出错.在使用s标签开启debug模式,并在struts2主配置文件中添加异常映射,再次提交表单后得到以下异常详情. org.springframewo ...
- Android开发从GC root分析内存泄漏
我们常说的垃圾回收机制中会提到GC Roots这个词,也就是Java虚拟机中所有引用的根对象.我们都知道,垃圾回收器不会回收GC Roots以及那些被它们间接引用的对象.但是,对于GC Roots的定 ...
- Tomcat下wtpwebapps文件夹 和 webapps文件夹区别
这两者其实没有区别.都是项目部署路径 webapps : tomcat默认部署路径 wtpwebapps : eclipse默认部署路径 只不过Tomcat6将wtpwebapps作为了默认路径,如果 ...
- Redis 中的数据类型及基本操作
Redis 内置的数据类型有 5种:字符串String.哈希Hash.列表List.集合Set.有序集合ZSet 字符串类型 String 是 Redis 中最基本的类型,一个 key 对应着一个 v ...
- 源码实现 --> strrev
字符串的顺序反序 函数 char *strrev(char *string); 将字符串string中的字符顺序颠倒过来. NULL结束符位置不变. 返回调整后的字符串的指针. 源码 //其基于的思想 ...
- Laravel 中缓存驱动的速度比较
缓存是web开发中重要的一部分,我相信很多人和我一样,经常忽略这个问题. 随着工作经验的累积,我已经意识到缓存是多么的重要,这里我通过 Scotch 来解释一下它的重要性. 通过观察发现,Scotch ...
- React Native 轻松集成统计功能(iOS 篇)
最近产品让我加上数据统计功能,刚好极光官方支持数据统计 支持了 React Native 版本 第一步 安装: 在你的项目路径下执行命令: npm install janalytics-react-n ...
- Leetcode 12——Integer to Roman
12.Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be withi ...
- 2017-2018-1 20155214&20155216 实验四:外设驱动程序设计
2017-2018-1 20155214&20155216 实验四:外设驱动程序设计 实验四外设驱动程序设计-1 实验要求: 学习资源中全课中的"hqyj.嵌入式Linux应用程序开 ...
- 2017-2018-1 1623 bug终结者 冲刺001
bug终结者 冲刺001 冲刺阶段任务分配 任务 工作量比例 完成时间 负责人 第一篇博客:各个成员的任务安排 1/7 12月1日 20162322 朱娅霖 第二篇博客:欢迎界面,主菜单界面 1/7 ...