码迷,mamicode.com
首页 > 其他好文 > 详细

【功能测试技巧3】多表提数实践

时间:2017-04-25 10:19:24      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:app   resource   _id   http   src   png   source   .com   business   

1.表table_score结构如下:用来存储分数。

技术分享

表table_no结构如下:用来存储相关合同号、签约号、保单号。

技术分享

表table_base结构如下:用来存储基础数据:

技术分享

我们现在想要取到三个表中以table_base为基础,与table_score,table_no关联的数据。

2.书写思路如下

(1)首先明确三个表中都有相同的字段apply_id、business_No

(2)其中business_NO与apply_id是一一对应的。

(3)其中table_base表中的一个apply_id对应表table_score中有多条记录。

3.写法如下

select a.apply_id,

    a.business_no,

          b.apply_id,

          b.app_no,

          b.policy_no,

(select score from table_score c where a.apply_id=c.apply_id and c.score_resource=‘01‘),

(select score from table_score d where a.apply_id=d.apply_id and d.score_resource=‘02‘),

 from   table_base a

left join table_no b on a.apply_id=b.apply_id;

说明如下:上述描述的写法需要注意以下问题:

(1)(select score from table_score c where a.apply_id=c.apply_id and c.score_resource=‘01‘)这里查询出来的也是一列元素;

(2)左连接左边的表必须只有一个,我们写的语句中是table_base;

(3)多个表中必须有一个相同的字段将三张表进行关联,否则无法实现多表查询的功能。

(4)写法上注意规律性:多个表一定运用别名。

select 后面就是写查询的字段

from后面就是跟的表名

如果有条件那么就用where和and等等条件语句。

 

【功能测试技巧3】多表提数实践

标签:app   resource   _id   http   src   png   source   .com   business   

原文地址:http://www.cnblogs.com/haibaowang/p/6758034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!