下表产品:
+--------------+-----------+--------+-----------+
| Product_code | Prod Name | Status | Date |
+--------------+-----------+--------+-----------+
| A | AA1 | New | 12/3/2019 |
| A | AA2 | Expiry | 7/20/2017 |
+--------------+-----------+--------+-----------+
预期产量:
+--------------+-----------+------------+-----------+------------+------------+
| Product_code | Min_date | Min_status | Max_date | Max_status | count_Prod |
+--------------+-----------+------------+-----------+------------+------------+
| A | 7/20/2017 | Expiry | 12/3/2019 | New | 2 |
+--------------+-----------+------------+-----------+------------+------------+
尝试以下查询
SELECT Product_code,MIN(Date) as "Min_date", MAX(Date) as
"Max_date",count(Prod_Name) as "count_Prod"
FROM Product where Product_code ='A'
GROUP BY Product_code
ORDER BY Product_code;
需要帮助来获取日期列的特定状态。
1条答案
按热度按时间gywdnpxw1#
请使用下面的查询。您也可以对字符串列使用min和max函数。它根据字母顺序进行聚合。