问题
Hi everybody I'm trying to combine two MySQL queries into only one.
I have two blocks, the FROM and the WHERE, I think they are the only ones needed in my case.
FROM:
FROM table1, table2, table3, table4, table5
WHERE:
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
And the other query is this:
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
Thanks to @Farhęg
I want that your_table is the result table of the query 1, or with restrictions FROM and WHERE that I already have.
How can I combine the two queries? Thanks!
来源:https://stackoverflow.com/questions/29337700/issue-combining-two-sql-queries