gpt4 book ai didi

mysql - 如果 endDate 中没有空值,则查找最大日期?

转载 作者:行者123 更新时间:2023-11-29 13:54:04 26 4
gpt4 key购买 nike

我的数据库中有以下行。

            profileID |     startDate     |   endDate
-------------------|-------------------|--------------
Jr.software eng. |2012-07-01 |2030-01-01
..................|...................|..............
Eng |2013-03-28 |2013-03-28
..................|...................|..............
Sr.eng |2013-04-09 |2013-04-17
..................|...................|..............
CEO |2012-11-21 |
..................|...................|..............

以上行存储在我的数据库中。我想要得到像这样的条件的结果。

1. If endDate is null then I get only it related startDate.

就像上面的行一样,我的预期结果是

        profileID  |     startDate     |   endDate
-------------------|-------------------|--------------
CEO |2012-11-21 |
..................|...................|..............
  1. 如果没有 null endDate,那么我想从 endDate 列表中获取最大 endDate。

但是如果行是这样的那么

           profileID  |     startDate     |   endDate
-------------------|-------------------|--------------
Jr.software eng. |2012-07-01 |2030-01-01
..................|...................|..............
Eng |2013-03-28 |2013-03-28
..................|...................|..............
Sr.eng |2013-04-09 |2013-04-17

那么我的预期结果是

           profileID  |     startDate     |   endDate
-------------------|-------------------|--------------
Jr.software eng. |2012-07-01 |2030-01-01
..................|...................|..............

我需要一个 mysql 查询。

最佳答案

Select profileId, Case When endate is NULL then startDate 
Else Max(EndDate) end As `Date`
From tablename

关于mysql - 如果 endDate 中没有空值,则查找最大日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16166328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com