如何在sql查询

时间:2015-09-12 14:58:40

标签: sql-server-2014

选择distinct(pc.id,pc.PolicyPremiumID),pc.policyPremiumCatID,b.nin,b.firstname +' &#39 +聚结((b.middleInitial)'')+' ' + b.lastname as fullname,b.gender,ppc.amount from bio_data b,medicalInsurance m,policy p,policyPremium pp,premiumCategories pc,policyPremiumCategory ppc 其中b.nin = m.patientBin和m.policyID = p.id和(p.id = pp.policyID和pp.policyID = p.id)和pp.id = pc.policyPremiumID和pc.policyPremiumcatID = ppc.id 和p.id = 82

在上面的查询中,我想要有这两列的不同 它是重复的,而不是它带来的7个返回值14 有人可以帮忙吗?在此先感谢!!!

1 个答案:

答案 0 :(得分:1)

使用以下方法:

列出所有值的示例选择查询:

mysql> select * from new_table;
+---------+------------+
| premium | sumassured |
+---------+------------+
|    1000 |     100000 |
|    2000 |     200000 |
|    3000 |     300000 |
|    1000 |     100000 |
|    1000 |     100000 |
|    3000 |     300000 |
|    4000 |     400000 |
+---------+------------+
7 rows in set (0.00 sec)

选择查询列出多个表中的不同值:

mysql> select distinct premium,sumassured from new_table;
+---------+------------+
| premium | sumassured |
+---------+------------+
|    1000 |     100000 |
|    2000 |     200000 |
|    3000 |     300000 |
|    4000 |     400000 |
+---------+------------+
4 rows in set (0.00 sec)

您可以对N行使用相同的行。