本文介绍了sql检索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表员工

emp_id | emp_name

01 |约翰

02 |米奇


表薪

s_id |收入| emp_id
1 | 10,000 | 02
2 | 20,000 | 01
3 | 5,000 | 02
4 | 2,000 | 01


我希望sql命令可以像这样输出数据:

约翰| 20,000 | 2,000
米奇10,000 | 5,000


请帮助我.我使用VB.NET编程语言

Table Employee

emp_id | emp_name

01 | john

02 | mitch


Table Salary

s_id | income | emp_id
1 | 10,000 | 02
2 | 20,000 | 01
3 | 5,000 | 02
4 | 2,000 | 01


I want sql command to output the data like this:

john | 20,000 | 2,000
mitch | 10,000 | 5,000


pls help me. I use VB.NET programming language

推荐答案


SELECT
  em.emp_name,
  sa.income
FROM
  Employee em
INNER JOIN
  Salary sa
ON em.emp_id = sa.emp_id



但是,此后您要问的是将所有相同的员工ID行数据整理为列数据.通过查询将不会很简单.我建议您采用上述查询数据,然后将其模制成前端所需的格式.



But, what you ask after this is to collate all the same employee id row data to column data. It would not be simple through query. I would suggest you to take the above query data and then mould it into the format required in your frontend.


with Employee_Sal as
(select A.emp_name,
B.income,
from Employee A join Salary B on A.emp_id = B.emp_id)


这篇关于sql检索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 05:29