09:24:16 SELECT name, 80 - tot_cred AS credits_left FROM student WHERE dept_name = 'Comp. Sci.' GROUP BY name HAVING credits_left > 0 ORDER BY credits_left ASC LIMIT 0, 10 Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'lab.student.tot_cred' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 0.000 sec

时间: 2024-03-26 10:38:37 浏览: 17
这个错误是由于在MySQL的新版本中,如果使用了`GROUP BY`语句,那么在`SELECT`语句中不能出现未被聚合的列。 你可以通过将`tot_cred`列聚合一下,或者将其加入到`GROUP BY`语句中来解决这个问题。 以下是修改后的MySQL语句: ``` SELECT name, 80 - SUM(tot_cred) AS credits_left FROM student WHERE dept_name = 'Comp. Sci.' GROUP BY name HAVING credits_left > 0 ORDER BY credits_left ASC LIMIT 0, 10; ``` 在这个语句中,我们使用了`SUM`函数将`tot_cred`列聚合起来,以便在`SELECT`语句中使用。 同时,我们也将`name`列加入到`GROUP BY`语句中。 这个修改后的语句应该可以正确地返回结果了。
相关问题

给出100条sql插入语句,插入表student,有ID,name,dept_name, tot_cred四个列,ID为五位int类型,tot_cred 为学分大于零小于150

以下是100条SQL插入语句,插入表student,有ID,name,dept_name, tot_cred四个列,其中ID为五位int类型,tot_cred 为学分大于零小于150: ``` INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10001, 'John Smith', 'Comp. Sci.', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10002, 'Jane Doe', 'Comp. Sci.', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10003, 'Bob Johnson', 'Comp. Sci.', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10004, 'Mary Lee', 'Comp. Sci.', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10005, 'Tom Brown', 'Comp. Sci.', 90); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10006, 'Sue Davis', 'Comp. Sci.', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10007, 'Jim Wilson', 'Comp. Sci.', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10008, 'Carol Smith', 'Comp. Sci.', 150); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10009, 'David Miller', 'Comp. Sci.', 80); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10010, 'Linda Johnson', 'Comp. Sci.', 95); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10011, 'Mike Brown', 'Comp. Sci.', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10012, 'Amy Lee', 'Comp. Sci.', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10013, 'Jack Davis', 'Comp. Sci.', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10014, 'Jill Wilson', 'Comp. Sci.', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10015, 'Sam Smith', 'Comp. Sci.', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10016, 'Janet Johnson', 'Comp. Sci.', 150); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10017, 'Bob Brown', 'Math', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10018, 'Mary Davis', 'Math', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10019, 'Tom Wilson', 'Math', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10020, 'Sue Smith', 'Math', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10021, 'Jim Lee', 'Math', 90); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10022, 'Carol Johnson', 'Math', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10023, 'David Brown', 'Math', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10024, 'Linda Davis', 'Math', 150); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10025, 'Mike Wilson', 'Math', 80); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10026, 'Amy Smith', 'Math', 95); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10027, 'Jack Lee', 'Math', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10028, 'Jill Johnson', 'Math', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10029, 'Sam Brown', 'Math', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10030, 'Janet Davis', 'Math', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10031, 'Bob Wilson', 'Physics', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10032, 'Mary Smith', 'Physics', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10033, 'Tom Lee', 'Physics', 90); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10034, 'Sue Johnson', 'Physics', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10035, 'Jim Brown', 'Physics', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10036, 'Carol Davis', 'Physics', 150); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10037, 'David Wilson', 'Physics', 80); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10038, 'Linda Smith', 'Physics', 95); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10039, 'Mike Lee', 'Physics', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10040, 'Amy Johnson', 'Physics', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10041, 'Jack Brown', 'Physics', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10042, 'Jill Davis', 'Physics', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10043, 'Sam Wilson', 'Physics', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10044, 'Janet Smith', 'Physics', 150); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10045, 'Bob Lee', 'Biology', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10046, 'Mary Johnson', 'Biology', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10047, 'Tom Brown', 'Biology', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10048, 'Sue Davis', 'Biology', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10049, 'Jim Wilson', 'Biology', 90); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10050, 'Carol Smith', 'Biology', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10051, 'David Miller', 'Biology', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10052, 'Linda Johnson', 'Biology', 150); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10053, 'Mike Brown', 'Biology', 80); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10054, 'Amy Lee', 'Biology', 95); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10055, 'Jack Davis', 'Biology', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10056, 'Jill Wilson', 'Biology', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10057, 'Sam Smith', 'Biology', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10058, 'Janet Johnson', 'Biology', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10059, 'Bob Brown', 'Chemistry', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10060, 'Mary Davis', 'Chemistry', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10061, 'Tom Wilson', 'Chemistry', 90); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10062, 'Sue Smith', 'Chemistry', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10063, 'Jim Lee', 'Chemistry', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10064, 'Carol Johnson', 'Chemistry', 150); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10065, 'David Brown', 'Chemistry', 80); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10066, 'Linda Davis', 'Chemistry', 95); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10067, 'Mike Wilson', 'Chemistry', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10068, 'Amy Smith', 'Chemistry', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10069, 'Jack Lee', 'Chemistry', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10070, 'Jill Johnson', 'Chemistry', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10071, 'Sam Brown', 'Geology', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10072, 'Janet Davis', 'Geology', 150); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10073, 'Bob Wilson', 'Geology', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10074, 'Mary Smith', 'Geology', 130); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10075, 'Tom Lee', 'Geology', 140); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10076, 'Sue Johnson', 'Geology', 100); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10077, 'Jim Brown', 'Geology', 90); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10078, 'Carol Davis', 'Geology', 110); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10079, 'David Wilson', 'Geology', 120); INSERT INTO student (ID, name, dept_name, tot_cred) VALUES (10080, 'Linda Smith', 'Geology', 150); ``` 注意:这些语句仅是示例,仅可用于学习和测试目的,不应用于实际生产环境。

为什么我使用上面这段代码后student表中的tot_cred变成了NULL??

可能是因为在执行触发器之前,student 表中的 tot_cred 字段已经被设置为 NULL。如果这是情况,那么在执行 UPDATE 语句时,tot_cred 字段的值将仍然是 NULL。为了解决这个问题,可以在 UPDATE 语句中使用 COALESCE 函数,将 NULL 值替换为 0。修改后的触发器代码如下所示: ``` create trigger tr_insert on takes for insert as declare @sno varchar(5) declare @cno varchar(5) declare @credit numeric(3,0) select @sno=ID,@cno=course_id from inserted select @credit=credits from course where course_id=@cno update student set tot_cred=COALESCE(tot_cred, 0) + @credit where ID=@sno go ``` 这样,即使 tot_cred 字段的值为 NULL,触发器也会将其视为 0,并将 @credit 值加到 tot_cred 中。

相关推荐

帮我把以下数据变成json格式:{ "switch_Cash": "Y", "pageMark": "add", "tx_date": "20230305", "cur_no": "1", "sfk_type": "03", "lease_type": "经营租赁", "change_rate": "0", "cap_name": "20220731SYZC000271", "lease_no": "20220731SYZC000271", "contract_key": "6980120220731001", "contract_name": "测试合同20220731-01", "bef_arch_area": "300", "bef_cash_rate: 2.38, "bill_type: 3, "bef_tax_rate: 5, "sfk_term: 4, "bef_tot_pay_time: 2, "bef_eve_amt: 22500, "exe_renew: N, "bef_renew_amt: 0, "bef_renew_eve_amt: 0, "bef_tot_pay_amt: 19047.62, "bef_unset_fin_exp: 221.39, "bef_contract_amt: 45000, "sige_date: 20220731, "bef_arch_position: 广州省佛山市宝芝林, "bef_effect_date: 20220801, "bef_mtr_date: 20240730, "bef_first_fk_date: 20220731,, "bef_renew_eft_date: , bef_renew_mtr_date: , aft_arch_area: 300, aft_bill_type: 3, aft_tax_rate: 5, aft_levy_rate: 5, aft_cash_rate: 2.38, aft_sfk_type: 03, aft_exe_renew: N, is_onchange: N, aft_sfk_term: 4, aft_contract_amt: 45000.00, aft_tot_pay_time: 2, aft_eve_amt: 22500, bef_renew_tot_pay_time: 0, max_term_seqn: 0, aft_effect_date: 20220801, aft_mtr_date: 20240730, aft_first_fk_date: 20220731, aft_renew_eft_date: , aft_renew_mtr_date: , bef_levy_rate: 5, cap_code: fjr0901, lease_no1: 20220731SYZC000271, aft_tot_pay_amt: 42857.14, aft_unset_fin_exp: 184.48999999999796, apply_amt: 23809.52, remark: test0609, change_valid_date: 20230609, cap_name_zh_: 测试资产-20230731-01, cur_no_zh_: 人民币, sfk_type_zh_: 周期性, flowable_: 1, flowable_targetNodeData: {"category":"CWSYS_69","isInput":"1","menuName":"使用权资产变更","pageNo":"cwsys_05_07"}, flowable_file_dataInfo: {"flowable_file_storeType":"undefined","flowable_file_split":false,"flowable_file_canDelete":true,"flowable_file_readOnly":false,"flowable_file_id":"FL-495eabb0-069c-11ee-9b92-59e9b66c35e6"}, cashList: [{"contract_no":"20220731HTXX000001","pay_date":"20220731","no":"20230201XJL000031","pay_amt":"25000.00","term_start_date":"20220801","create_trace_no":"16","tx_date":"0","trace_no":"0","term_end_date":"20230731","pay_sts":"未支付","version":"1","tax_rate":"0.00","term_seqn":"1","tax_amt":"1190.48","pay_sts_val":"0","id":"1","create_date":"20230201","levy_rate":"0.00"},{"contract_no":"20220731HTXX000001","pay_date":"20230731","no":"20230201XJL000032","pay_amt":"20000.00","term_start_date":"20230731","create_trace_no":"16","tx_date":"0","trace_no":"0","term_end_date":"20240730","pay_sts":"未支付","version":"1","tax_rate":"0.00","term_seqn":"2","tax_amt":"952.38","pay_sts_val":"0","id":"1","create_date":"20230201","levy_rate":"0.00"}] }

最新推荐

recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB结构体与对象编程:构建面向对象的应用程序,提升代码可维护性和可扩展性

![MATLAB结构体与对象编程:构建面向对象的应用程序,提升代码可维护性和可扩展性](https://picx.zhimg.com/80/v2-8132d9acfebe1c248865e24dc5445720_1440w.webp?source=1def8aca) # 1. MATLAB结构体基础** MATLAB结构体是一种数据结构,用于存储和组织相关数据。它由一系列域组成,每个域都有一个名称和一个值。结构体提供了对数据的灵活访问和管理,使其成为组织和处理复杂数据集的理想选择。 MATLAB中创建结构体非常简单,使用struct函数即可。例如: ```matlab myStruct
recommend-type

详细描述一下STM32F103C8T6怎么与DHT11连接

STM32F103C8T6可以通过单总线协议与DHT11连接。连接步骤如下: 1. 将DHT11的VCC引脚连接到STM32F103C8T6的5V电源引脚; 2. 将DHT11的GND引脚连接到STM32F103C8T6的GND引脚; 3. 将DHT11的DATA引脚连接到STM32F103C8T6的GPIO引脚,可以选择任一GPIO引脚,需要在程序中配置; 4. 在程序中初始化GPIO引脚,将其设为输出模式,并输出高电平,持续至少18ms,以激活DHT11; 5. 将GPIO引脚设为输入模式,等待DHT11响应,DHT11会先输出一个80us的低电平,然后输出一个80us的高电平,
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB结构体与数据库交互:无缝连接数据存储与处理,实现数据管理自动化

![MATLAB结构体与数据库交互:无缝连接数据存储与处理,实现数据管理自动化](https://ww2.mathworks.cn/products/database/_jcr_content/mainParsys/band_1749659463_copy/mainParsys/columns_copy/6d5289a2-72ce-42a8-a475-d130cbebee2e/image_copy_2009912310.adapt.full.medium.jpg/1709291769739.jpg) # 1. MATLAB结构体与数据库交互概述** MATLAB结构体与数据库交互是一种强大的
recommend-type

Link your Unity

project to C# script in Visual Studio. Can you provide me with some guidance on this? Yes, I can definitely help you with that! To link your Unity project to C# script in Visual Studio, you first need to make sure that you have both Unity and Visual Studio installed on your computer. Then, you can
recommend-type

c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf

校园超市商品信息管理系统课程设计旨在帮助学生深入理解程序设计的基础知识,同时锻炼他们的实际操作能力。通过设计和实现一个校园超市商品信息管理系统,学生掌握了如何利用计算机科学与技术知识解决实际问题的能力。在课程设计过程中,学生需要对超市商品和销售员的关系进行有效管理,使系统功能更全面、实用,从而提高用户体验和便利性。 学生在课程设计过程中展现了积极的学习态度和纪律,没有缺勤情况,演示过程流畅且作品具有很强的使用价值。设计报告完整详细,展现了对问题的深入思考和解决能力。在答辩环节中,学生能够自信地回答问题,展示出扎实的专业知识和逻辑思维能力。教师对学生的表现予以肯定,认为学生在课程设计中表现出色,值得称赞。 整个课程设计过程包括平时成绩、报告成绩和演示与答辩成绩三个部分,其中平时表现占比20%,报告成绩占比40%,演示与答辩成绩占比40%。通过这三个部分的综合评定,最终为学生总成绩提供参考。总评分以百分制计算,全面评估学生在课程设计中的各项表现,最终为学生提供综合评价和反馈意见。 通过校园超市商品信息管理系统课程设计,学生不仅提升了对程序设计基础知识的理解与应用能力,同时也增强了团队协作和沟通能力。这一过程旨在培养学生综合运用技术解决问题的能力,为其未来的专业发展打下坚实基础。学生在进行校园超市商品信息管理系统课程设计过程中,不仅获得了理论知识的提升,同时也锻炼了实践能力和创新思维,为其未来的职业发展奠定了坚实基础。 校园超市商品信息管理系统课程设计的目的在于促进学生对程序设计基础知识的深入理解与掌握,同时培养学生解决实际问题的能力。通过对系统功能和用户需求的全面考量,学生设计了一个实用、高效的校园超市商品信息管理系统,为用户提供了更便捷、更高效的管理和使用体验。 综上所述,校园超市商品信息管理系统课程设计是一项旨在提升学生综合能力和实践技能的重要教学活动。通过此次设计,学生不仅深化了对程序设计基础知识的理解,还培养了解决实际问题的能力和团队合作精神。这一过程将为学生未来的专业发展提供坚实基础,使其在实际工作中能够胜任更多挑战。
recommend-type

关系数据表示学习

关系数据卢多维奇·多斯桑托斯引用此版本:卢多维奇·多斯桑托斯。关系数据的表示学习机器学习[cs.LG]。皮埃尔和玛丽·居里大学-巴黎第六大学,2017年。英语。NNT:2017PA066480。电话:01803188HAL ID:电话:01803188https://theses.hal.science/tel-01803188提交日期:2018年HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaireUNIVERSITY PIERRE和 MARIE CURIE计算机科学、电信和电子学博士学院(巴黎)巴黎6号计算机科学实验室D八角形T HESIS关系数据表示学习作者:Ludovic DOS SAntos主管:Patrick GALLINARI联合主管:本杰明·P·伊沃瓦斯基为满足计算机科学博士学位的要求而提交的论文评审团成员:先生蒂埃里·A·退休记者先生尤尼斯·B·恩