如何在sql server中获取结果集 [英] How to get result set in sql server

查看:206
本文介绍了如何在sql server中获取结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everybody,



我的结果集是

Hello Everybody,

My result set is

emp_id   year  month   salary
------------------------------------
 1       2014   4     4500
 1       2014   5     5640
 1       2013   7     4530





是否有可能获得结果



Whether it is possible to get result like

emp_id    year    month     salary
-------------------------------------------
 1        2014     4         4500
                   5         5600

          2013     7         4530



在sql server 2008中。



先谢谢。


in sql server 2008.

Thanks in Advance.

推荐答案

检查此查询是否简化并构建了这个



你的表结构,其值为



check this query simplify and build from this

ur table structure with values

CREATE TABLE employeeTemp (emp_id varchar(50), year varchar(50),month bigint,salary DECIMAL(6, 2))
INSERT INTO employeeTemp
VALUES   ('1','2014',4,4500),('1','2014',5,5600),('1','2013',7,4530)
;





选择查询



select query

with temp as
(SELECT emp_id, year,month,salary, row_number() over(partition by emp_id order by emp_id) rn
FROM   employeeTemp as b)
SELECT Case WHEN rn>1 THEN '' ELSE emp_id END as emp_id,year,month,salary  into #temp from temp
order by  year desc
;
with temp1 as
(SELECT emp_id, year,month,salary, row_number() over(partition by year order by year) rn
FROM   #temp as b)
SELECT emp_id,Case WHEN rn>1 THEN '' ELSE year END as year,month,salary  from temp1
order by  month asc







祝你好运;-)




good luck ;-)


这可能看起来很学术,但它是解决问题的关键:结果集是一回事,它向用户显示的方式是另一回事。

您已经获得了正确的结果,这是一个良好的开端。现在是时候用您熟悉的编程语言设计一个GUI,您可以按照所需的方式显示它。
This may look rather academic, but it is the key to solving the problem: the result set is one thing, the way it is displayed to the user is a different thing.
You get the correct result already, that is a good start. And now it is time to design a GUI in a programming language you are comfortable with where you can show it in the way desired.


这篇关于如何在sql server中获取结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆