php - SELECT records WHERE rows have difference on a specific column -


i have database table campaign_data. need select customer_id in campaign there difference in tariff. how can mysql query. here sample data.

sql fiddle schema

| campaign_id | customer_id |    campaign_name | tariff | --------------------------------------------------------- |           1 |           1 |         richmond |    100 | |           2 |           1 | sutton coldfield |     75 | |           3 |           1 |           putney |    100 | |           4 |           1 |     kentish town |    100 | |           5 |           1 |           woking |    100 | |           6 |           2 |         chiswick |     90 | |           7 |           2 |           ealing |    100 | |           8 |           2 |           camden |    100 | |           9 |           3 |          croydon |     75 | |          10 |           3 |         croydon1 |    100 | |          11 |           3 |          archway |    100 | |          12 |           4 |          ealing0 |    100 | |          13 |           4 |         ealing01 |    100 | |          14 |           4 |         ealing02 |    100 | |          15 |           4 |        chingford |    100 | |          16 |           4 |      chingford01 |    100 | 

now can see customer id 1 , , 3 has different tariffs. want select them , leave customer id 4 because has campaigns same tariffs.

desired output

| customer_id | --------------- |           1 | |           2 | |           3 | 

for clearification can see customer 1 has 5 records. if in 5 records tariff same (100) want avoid if tariff not 4 records have 100 , 1 has 75, want select.

select customer_id, count(distinct tariff) tariffs  campaign_data  group customer_id  having tariffs > 1 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -