再来一个ChatGPT编程,这回是SQL。这个我都没写出来。大家看看问题的描述能看懂不?再看看ChatGPT给的代码对不对?

对应老买买提的军事天地,观点交锋比较激烈,反驳不留情面,请作好心理准备。因为此版帖子太多,所以新帖不出现在首页新帖列表,防止首页新帖刷屏太快。


版主: Softfist

回复
头像
TheMatrix楼主
论坛元老
论坛元老
2024年度优秀版主
TheMatrix 的博客
帖子互动: 293
帖子: 13895
注册时间: 2022年 7月 26日 00:35

再来一个ChatGPT编程,这回是SQL。这个我都没写出来。大家看看问题的描述能看懂不?再看看ChatGPT给的代码对不对?

帖子 TheMatrix楼主 »

Given a SQL table "Account" with a unique increasing "AccountID" field and an integer field "AccountSize". Write a SQL to assign consecutive AccountIDs to a group with "GroupID" such that the sum of AccountSize in each group is just below a given threshold, say 1000.

代码: 全选

WITH cte AS (
  SELECT
    AccountID,
    AccountSize,
    SUM(AccountSize) OVER (ORDER BY AccountID) AS RunningTotal,
    ROW_NUMBER() OVER (ORDER BY AccountID) AS RowNum
  FROM Account
),
cte2 AS (
  SELECT
    AccountID,
    AccountSize,
    RunningTotal,
    RowNum,
    CASE
      WHEN RunningTotal - AccountSize < 1000 THEN RowNum
      ELSE RowNum - 1
    END AS GroupID
  FROM cte
)
SELECT
  AccountID,
  AccountSize,
  GroupID
FROM cte2
ORDER BY AccountID;
wyr
正式会员
正式会员
帖子互动: 1
帖子: 27
注册时间: 2022年 7月 24日 00:11

Re: 再来一个ChatGPT编程,这回是SQL。这个我都没写出来。大家看看问题的描述能看懂不?再看看ChatGPT给的代码对不对?

帖子 wyr »

obviously wrong
头像
TheMatrix楼主
论坛元老
论坛元老
2024年度优秀版主
TheMatrix 的博客
帖子互动: 293
帖子: 13895
注册时间: 2022年 7月 26日 00:35

Re: 再来一个ChatGPT编程,这回是SQL。这个我都没写出来。大家看看问题的描述能看懂不?再看看ChatGPT给的代码对不对?

帖子 TheMatrix楼主 »

wyr 写了: 2023年 2月 11日 17:35obviously wrong
嗯。我也觉得它给的这个太简单了。

问题描述能看懂吧?
回复

回到 “军事天地(Military)”