sql - insert into a table with select
问题描述
I have two tables with these schema:
student(id,name,dept_name, tot_cred)
instructor(id,name,dept_name,salary)
and the question is:
Insert every student whose tot_cred attribute is greater than 100 as an instructor in the same department, with a salary of $10,000.
I try this query but I dont know how set salary for student $10,000:
insert into instructor (id,name,dept_name,salary)
select id,name,dept_name
from student
where tot_cred > 100
解决方案
Just select the constant value. Personally, I'd add an alias in the select
to document that the constant is intended to be the salary
although it's not necessary. Different databases may have different rules for how to create that alias and you haven't told us what database you're using so I'm guessing on the syntax.
insert into instructor (id,name,dept_name,salary)
select id,name,dept_name,10000 as salary
from student
where tot_cred > 100
推荐阅读
- r - 我们如何在两行中显示 F 统计量/自由度
- php - 在 WooCommerce 中禁用特定优惠券代码的免费送货
- ios - SwiftUI EnvironmentObject 与 View 不同步
- c# - unity 填充量 lerp
- reactjs - 是否可以使用 React 组件编写 AEM 体验片段,然后提供无头前端?
- swift - Swift 在 macOS 中以编程方式打开新窗口
- python-3.x - 在 PyVista 中向 PolyData 添加新点/将 XYZ 处理为 TIN 的最佳方式
- c++ - 如何使用 g++ (MSYS2/MinGW) 在 Windows 上根据 Google 的灯丝库编译 C++ 项目?
- oracle - ORACLE APEX APP 中的登录凭据无效
- c - 错误:函数“sysconf”的隐式声明