结合两个SQL查询的问题

时间:2015-03-30 02:55:41

标签: mysql sql join group-by

大家好,我试图将两个MySQL个查询合并为一个。

我有两个区块,FROMWHERE,我认为它们是我个案中唯一需要的区块。

FROM:

FROM table1, table2, table3, table4, table5

其中:

WHERE field1 = 1
  AND (field2 = 3 OR field2 = 4)
  AND (table5.field3 <= 100000)
  AND (table5.field4 >= 1)
  AND (table5.field5 >= 1)
  AND (table5.field6 >= 60)
  AND table5.field2 = table4.id
  AND table5.field7 = table3.field8
  AND table3.field9 = table1.field10
  AND table3.field11 = table2.field12

另一个问题是:

select t.txt, count(t.age) from 
(select 
  case 
      when age<11 then concat(age ,' year') 
      else 'more than 10' 
  end txt, age
from your_table)t
group by t.txt
order by 1

感谢@Farhęg

我希望your_table是查询1的结果表,或者是我已经拥有的限制FROMWHERE

如何合并这两个查询?谢谢!

0 个答案:

没有答案