You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求TEACHER_TB中ID为1、2、3、4的教师基础数据总和

Got it, let's tackle this problem step by step. Based on your requirement and the provided table structure/data, here's the solution broken down clearly:

解决方案

First, we need to clarify what "sum of basic data" refers to. From your table structure, the numeric fields are TEACHER_ID (primary key, summing this has no practical business meaning), SALARY_ID, and SUBJECT_ID. Below are solutions for different scenarios:

1. Sum numeric fields directly from TEACHER_TB

If you want to calculate the total of SALARY_ID and SUBJECT_ID for teachers with IDs 1-4, use this SQL query:

SELECT 
    SUM(SALARY_ID) AS total_salary_id,
    SUM(SUBJECT_ID) AS total_subject_id
FROM TEACHER_TB
WHERE TEACHER_ID IN (1, 2, 3, 4);

Calculation Result

Using the provided data:

  • total_salary_id = 1 + 3 + 3 + 2 = 9
  • total_subject_id = 2 + 4 + 8 + 6 = 20

2. Calculate actual salary total by joining the salary table

Since SALARY_ID is a foreign key linked to salary_tb, if "basic data sum" refers to the total salary amount of these teachers, you need to join the two tables (assuming salary_tb has SALARY_ID and SALARY_AMOUNT fields):

SELECT 
    SUM(s.SALARY_AMOUNT) AS total_salary_amount
FROM TEACHER_TB t
JOIN SALARY_TB s 
    ON t.SALARY_ID = s.SALARY_ID
WHERE t.TEACHER_ID IN (1, 2, 3, 4);

Note

Since you haven't provided the specific data of salary_tb, this query is for reference only. You can substitute the actual salary data to get the final total.


内容的提问来源于stack exchange,提问作者kuwar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:00:08