[英]Aggregate function along other records
Let's say I am going to fetch all records of table T1
. 假设我要获取表
T1
所有记录。 Also, I need to have access to min
and max
date value of records. 另外,我需要访问记录的
min
和max
日期值。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.