简体   繁体   中英

Aggregate function along other records

Let's say I am going to fetch all records of table T1 . Also, I need to have access to min and max date value of records.

I may do that using two queries:

select * from T1 ;
select min(created_at) as min_date,max(created_at) as max_date from T1;

This is two separate queries , but is it possible to have them in one query?
I mean all records plus min and max value of a specific column.

select *,
       (select min(created_at) from T1) as min_date,
       (select max(created_at) from T1) as max_date
from T1;
SELECT * FROM `T1` JOIN (SELECT MIN(`created_at`) AS min_date,
MAX(`created_at`) AS max_date FROM `T1` ) AS temp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM