合并多行数据 [英] Combining data in multiple rows

查看:52
本文介绍了合并多行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 SQL 教程,但在我有多行具有相同顺序的问题上遇到了麻烦#--如何将具有相同顺序的所有行合并为一行?

I'm following a SQL tutorial and am having trouble with this problem where I have multiple rows with the same order#-- how can I consolidate all rows with the same order# into just one row?

例如,在屏幕截图中,前 2 行是关于Jake Lucas"并且具有相同的顺序#:我需要做什么才能将这 2 行变成 1 行?

So for example, in the screenshot, the first 2 rows are about "Jake Lucas" and have the same order#: what do I need to do to make these 2 rows into 1 row?

这是我的代码:

SELECT firstName || ' ' || lastname "Name", customer#, order#, quantity, 
paideach, (quantity * paideach) "TOTAL", state

FROM orderitems JOIN orders USING (order#) JOIN customers USING (customer#)

WHERE (state = 'FL' OR state = 'GA');

推荐答案

我不知道你的语法格式,看来你正在使用一个框架左右..

I don't know about your syntax format, It seems you are using a framework or so..

但是如果你想合并相同的订单#那么你可以查看 GROUP BY SQL 语句..

But if you want to combine the same order# then you can check out GROUP BY SQL Statement..

你可以尝试把它放在WHERE子句之后,试试... WHERE (state = 'FL' OR state = 'GA') GROUP BY (order#)

You can try to put it after the WHERE clause, try ... WHERE (state = 'FL' OR state = 'GA') GROUP BY (order#)

更多详情:http://www.w3schools.com/sql/sql_groupby.asp

这篇关于合并多行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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