这是我的数据表:
| uid | date | visit | transactionDate |
+-----+----------+-------+-----------------+
| 1 | 6/2/2014 | 1 | 6/9/2014 |
| 1 | 6/2/2014 | 1 | 8/4/2014 |
| 2 | 6/2/2014 | 1 | 8/2/2014 |
| 2 | 6/2/2014 | 1 | 10/17/2014 |
| 2 | 6/2/2014 | 1 | 10/20/2014 |
| 3 | 6/2/2014 | 1 | 6/9/2014 |
| 3 | 6/2/2014 | 1 | 6/10/2014 |
| 3 | 6/2/2014 | 1 | 6/11/2014 |
| 3 | 6/2/2014 | 1 | 6/12/2014 |
| 3 | 6/2/2014 | 1 | 6/14/2014 |
| 3 | 6/2/2014 | 1 | 6/15/2014 |
| 3 | 6/2/2014 | 1 | 6/17/2014 |
| 3 | 6/2/2014 | 1 | 6/18/2014 |
| 3 | 6/2/2014 | 1 | 6/23/2014 |
我正在尝试编写一个查询来提取两列日期和交易日期中的最小值。有没有办法做类似 MIN(date, transactionDate) 的事情?查询应选择如下内容:
uid 1 then minimum of date and transaction_dt
uid 2 then min date and transaction_dt
最佳答案
使用CASE
条件。
SELECT uid, visit,
CASE WHEN date < transactionDate THEN date ELSE transactionDate END AS minDate
FROM table;
关于mysql - 获取每行两列之间的最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27372259/