2013-04-05 44 views
-1

我用这个代码哈瓦数据库如何选择从数据库代码

间接客户 卡斯特码 疗养院NH000001 牙医DN000001 其他OT000001

和直接客户 卡斯特码 疗养院NH050001 牙医DN050001 其他OT050001

NH后的注意00有间接定制对于直接客户

ER和05我需要编写一个查询来获取直接和间接客户

SELECT * FROM bmwregistration ,corporation_data_entity,category_data_entity,ward_data_entity 
       Where occu_corp_id='$corpo'   
       AND occu_division = '$divi' 
       AND bmwregistration.occu_corp_id = corporation_data_entity.corp_id 

       AND bmwregistration.occu_ward = ward_data_entity.ward_id 
       AND (cust_code LIKE '%BB00%' 
       OR cust_code LIKE '%DP00%' 
       OR cust_code LIKE '%NH00%' 
       OR cust_code LIKE '%PL00%' 
       OR cust_code LIKE '%DN00%' 
       OR cust_code LIKE '%OT00%' 
       OR cust_code LIKE '%PD00%' 
       OR cust_code LIKE '%PN00%') 

的名单上面时执行查询它显示的一行相同的卡斯特码8倍。我可以使用group by子句吗?查询有什么问题?

它在连续八线 卡斯特码

1 
1 
1 
1 
1 
1 
1 
1 
2 
2 
2 
2 
2 
2 
2 
2 
3(8 times same row with cust_id 3) 
+0

一个问题,也许尝试呢? – DessDess 2013-04-05 12:39:05

+0

恐怕问题不清楚! – 2013-04-05 12:39:55

+0

JoshL,nneonneo,legoscia,Aleksandr M,David你现在可以重新打开问题吗? – 2014-04-07 12:07:27

回答

2

选择与同一客户码的行与group by

SELECT * FROM bmwregistration ,corporation_data_entity,category_data_entity,ward_data_entity 
      Where occu_corp_id='$corpo'   
      AND occu_division = '$divi' 
      AND bmwregistration.occu_corp_id = corporation_data_entity.corp_id 

      AND bmwregistration.occu_ward = ward_data_entity.ward_id 
      AND (cust_code LIKE '%BB00%' 
      OR cust_code LIKE '%DP00%' 
      OR cust_code LIKE '%NH00%' 
      OR cust_code LIKE '%PL00%' 
      OR cust_code LIKE '%DN00%' 
      OR cust_code LIKE '%OT00%' 
      OR cust_code LIKE '%PD00%' 
      OR cust_code LIKE '%PN00%') 
     GROUP BY bmwregistration