combine 4 queries in one
Just do it in the client if you must.

SELECT *
FROM product
WHERE add_time &gt;= NOW() - interval '30 day';


But if you must you can offload some of this to the server, thought I wouldn't because it's largely view-logic.

SELECT
  add_time &gt;= NOW() - interval '12 hours' AS 12_hours,
  add_time &gt;= NOW() - interval '24 hours' AS 24_hours,
  add_time &gt;= NOW() - interval '7 day' AS 7_day,
  *
FROM product
WHERE add_time &gt;= NOW() - interval '30 day';


You could also put it all into a case statement if you really wanted...

SELECT
  CASE
    WHEN add_time &gt;= NOW() - interval '12 hours' THEN '12h'
    WHEN add_time &gt;= NOW() - interval '24 hours' THEN '24h'
    WHEN add_time &gt;= NOW() - interval '7 day' THEN '7d'
  END,
  *
FROM product
WHERE add_time &gt;= NOW() - interval '30 day';