mysql - How to equiry data using sql when facing condition? -
type cost 10 11 12 b 10 b 10
i have small sample table. want select data cost of same type different.so expected outcome should be:
type cost 10 11 12
the cost different need select these "a" out. "select" sentence?
thanks replies. table little more complex
type cost people 10 jack 11 frank 12 lucy b 10 amy b 10 tom
i need select data meet 1 of requirements below:
- same type different cost
- same type people "amy"
so outcome should :
type cost people 10 jack 11 frank 12 lucy b 10 amy b 10 tom
select of type because cost different select of type b because people has "amy" have firgure out how select amy this:
select type, cost, people table type in (select type table people = 'amy')
i don't know how combine these conditions. sql fiddle
you can use exists
row same type other cost:
select t1.type, t1.cost tablename t1 exists (select * tablename t2 t2.type = t1.type , t2.cost <> t1.cost)
or have sub-query returns type values having different costs, , join result:
select t1.type, t1.cost tablename t1 join (select type tablename group type having max(cost) <> min(cost)) t2 on t1.type = t2.type
Comments
Post a Comment