Combining data in multiple rows

天涯浪子 提交于 2019-12-25 00:40:22

问题


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?

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?

Here's my code:

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');


回答1:


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

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

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

more details: http://www.w3schools.com/sql/sql_groupby.asp



来源:https://stackoverflow.com/questions/23359809/combining-data-in-multiple-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!