如何在sql server中的同一个表中合并两行? [英] How to merge two rows in same table in sql server?

查看:120
本文介绍了如何在sql server中的同一个表中合并两行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql server 2008中有以下格式的数据



I have data in the following format in sql server 2008

userid   testid   catid    correct      incorrect
2         1        1       18           NULL
2         1        2        1           NULL
2         1        1       NULL          5
2         1        2       NULL           1





i必须使其符合以下格式:



i have to make it into the following format:

userid   testid   catid    correct      incorrect
2         1        1       18           5
2         1        2        1           1



请帮我解决问题。


please help me to solve the problem.

推荐答案

你可以试试这个:

You may try this:
SELECT userid, testid, catid, max(correct), max(incorrect)
FROM [your table]
GROUP BY userid, testid, catid


这篇关于如何在sql server中的同一个表中合并两行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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