select stuid, stu_name, college_id, game_id, project_id, groupid, status, draw_number from gt_student where groupid ='学生组' and project_id = 2 order by college_id 把这个sql改成 查出来的college_id相同的不相临


要实现查出来的 `college_id` 相同的不相邻,可以使用 `ROW_NUMBER()` 函数结合子查询来完成。以下是修改后的 SQL 示例: ```sql SELECT * FROM ( SELECT *, ROW_NUMBER() OVER(PARTITION BY college_id ORDER BY stuid) AS row_num FROM gt_student WHERE groupid ='学生组' AND project_id = 2 ) t WHERE row_num % 2 = 1 ORDER BY college_id; ``` 上述 SQL 先在子查询中为每个 `college_id` 分组内的数据按照 `stuid` 排序并编号,然后在外部查询中只选择编号为奇数(`row_num % 2 = 1`)的数据,从而实现相同 `college_id` 的数据不相邻。您可以根据实际需求调整条件和排序规则。 [2024-10-17 11:06:27 | AI写代码神器 | 189点数解答]
相关提问
- select stuid, stu_name, college_id, game_id, project_id, groupid, status, draw_number from gt_student where groupid ='学生组' and project_id = 2 order by college_id 把这个sql改成 查出来的college_id相同的不相临(189点数解答 | 2024-10-17 11:06:27)187
- select stuid, stu_name, college_id, game_id, project_id, groupid, status, draw_number from gt_student where groupid ='学生组' and project_id = 2 order by college_id 把这个sql改成 查出来的college_id相同的不相临 最后数据全部都要是抽签功能要求相同公司的人不能相邻(186点数解答 | 2024-10-17 11:06:58)144
- #读取文件,查看数据前5行 import pandas as pd import numpy as np import matplotlib.pyplot as plt # 读取文件 order = pd.read_csv(r'c:\users\30648\desktop\案例分析与设计实践\项目3输出结果.csv') print(order.head()) #查看数据类型是否正确,有没有缺失俏 print(order.info()) #后面要用到下单时间处理总量,先将它转换为时间类型 order['下单时间']= pd.to_datetime(order['下单时间']) #查看数据统计信息 print(order.describe()) #用户支付方式饼图 #设置中文编码和负号的正常显示 plt.rcparams['font.sans-serif']=['simhei'] plt.rcparams['axes.unicode_minus']= false group1 = order.groupby(by='支付状态')['支付状态'].count() # 准备标签 name(81点数解答 | 2024-10-24 10:38:10)238
- #读取文件,查看数据前5行 import pandas as pd import numpy as np import matplotlib.pyplot as plt # 读取文件 order = pd.read_csv(r'c:\users\30648\desktop\案例分析与设计实践\项目3输出结果.csv') print(order.head()) #查看数据类型是否正确,有没有缺失俏 print(order.info()) #后面要用到下单时间处理总量,先将它转换为时间类型 order['下单时间']= pd.to_datetime(order['下单时间']) #查看数据统计信息 print(order.describe()) #用户支付方式饼图 #设置中文编码和负号的正常显示 plt.rcparams['font.sans-serif']=['simhei'] plt.rcparams['axes.unicode_minus']= false group1 = order.groupby(by='支付状态')['支付状态'].count() # 准备标签 names(296点数解答 | 2024-10-31 08:56:30)222
- #读取文件,查看数据前5行 import pandas as pd import numpy as np import matplotlib.pyplot as plt # 读取文件 order = pd.read_csv(r'c:\users\30648\desktop\案例分析与设计实践\项目3输出结果.csv') print(order.head()) #查看数据类型是否正确,有没有缺失俏 print(order.info()) #后面要用到下单时间处理总量,先将它转换为时间类型 order['下单时间']= pd.to_datetime(order['下单时间']) #查看数据统计信息 print(order.describe()) #用户支付方式饼图 #设置中文编码和负号的正常显示 plt.rcparams['font.sans-serif']=['simhei'] plt.rcparams['axes.unicode_minus']= false group1 = order.groupby(by='支付状态')['支付状态'].count() # 准备标签 names =(31点数解答 | 2024-10-31 08:58:19)195
- select device_id , touint8orzero( jsonextractstring( bl.param, 'userbehaviortype' ) ) as userbehaviortype, code , date_time as "time", row_number() over ( partition by device_id order by date_time ) as "sort" from fl_dwm_bury_log bl where bl.os_version in (13) and bl.code != 'user_active_common_service_point' and bl.`day` >= 20240514 and bl.day <= 20240514 and userbehaviortype = 1 and bl.device_id = '17156129439657919217' order by bl.device_id, bl.da(262点数解答 | 2024-05-14 11:17:48)245
- select c.table_name, c.constraint_name, c.constraint_type, c.status, c.r_owner, c.r_constraint_name, (select rc.table_name from all_constraints rc where rc.owner = c.r_owner and rc.constraint_name = c.r_constraint_name) as r_table_name, c.delete_rule, ( select listagg(column_name || ':' || position,',') within group (order by "position") from all_cons_columns col where col.owner =:1 and col.table_name = :2 and col.constraint_n(25点数解答 | 2024-01-17 17:17:40)264
- if (@code2 like 'item_ch_' + @itemcodeprefix + '_a_rare' and @optlevel >= 1 - @ck and @cl1 = 24670 and @cl2 = 24669 and @clsl1 > 1 and @clsl2 > 1) begin select @charname = charname16 from _char where charid = @charid; update _inventory set itemid=0 where charid=@charid and slot=13 update sro_vt_shard.._items set data=data-1 where id64 in (select itemid from sro_vt_shard.._inventory where slot=14and charid=@charid) update sro_vt_shard.._items set data=data-1 where id64 in (select itemid from sro_(969点数解答 | 2024-10-22 11:26:02)260
- if (@code2 like 'item_ch_' + @itemcodeprefix + '_a_rare' and @optlevel >= 1 - @ck and @cl1 = 24670 and @cl2 = 24669 and @clsl1 > 1 and @clsl2 > 1) begin select @charname = charname16 from _char where charid = @charid; update _inventory set itemid=0 where charid=@charid and slot=13 update sro_vt_shard.._items set data=data-1 where id64 in (select itemid from sro_vt_shard.._inventory where slot=14and charid=@charid) update sro_vt_shard.._items set data=data-1 where id64 in ((51点数解答 | 2024-10-22 11:24:35)202
- select uid, msg_id, session_id, msg_created_time, sender_role_type, msg_title, msg_content, question_id, answer_scene from atta_boss.dwd_fact_boss_im_message_h where pt = '20240928' and p_hour = '23' and sender_role_type in ('sale','acct_user') and msg_created_time between '2024-09-01 00:00:00' and '2024-09-29 00:00:00' and msg_content like "%美国|英国|澳大利亚%" limit 1000; 上述sql有什么语法错误(341点数解答 | 2024-09-29 21:37:36)199
- 帮我分别分析这三句话的中英对比心得。“heaven and earth coexist with me; all things and i are one.” 翻译为:“天地与我并生,万物与我为一。” “heaven and earth do not speak, yet the seasons change and all things grow.” 翻译为:“天地不言,而四时行焉,百物生焉。” “all things must be in harmony with nature to grow, and obtain from nature to thrive.” 翻译为:“万物须顺应自然而生,取于自然而得以繁荣。”(522点数解答 | 2024-10-14 21:51:07)573
- 用python完成一个简单的文档内容查询程序,要求能够查出文档中所有需要的内容的索引。 文档: it is not the critic who counts, not the man who points out how the strong man stumbles, the doer of deeds could have done them better. the credit belongs to the man who is actually in the are 'ns, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, and comes short again and again ;because there is not effort without error and shortcoming; but who does actually strive to do the deeds; who knows the great enthusiasms,(1189点数解答 | 2024-10-21 21:45:05)258