问题
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