Q:

How to connect two sql queries?

I am trying to connect two queries referring to the same table. I want to know how many fruits I got in the time range and how many of them were not fresh.
Query 1
SELECT COUNT(id) FROM fruits
WHERE date>='2017-04-01' AND date<='2017-04-30'

Query 2
SELECT COUNT(id) FROM fruits
WHERE fresh='no'

A:

You can use a CASE expression (NB: I am interpreting the "of them" in the question to be referring to fruits in the time range not fruits in general if you want fruits in general remove the where clause and move the predicate into another similar case expression)
SELECT COUNT(id), 
       SUM(CASE WHEN fresh = 'no' THEN 1 ELSE 0 END)
FROM fruits
WHERE date>='2017-04-01' AND date<='2017-04-30'

