1

我有两张桌子

第一个看起来像这样:

Name|Sir Name|Adress
Max1|Musterma|Muster Street
Max2|Musterma|Muster Street
Max3|Musterma|Muster Street
Max4|Musterma|Muster Street
Max5|Musterma|Muster Street

第二个看起来像这样:

Name|Money
Max3|50.00
Max1|40.00
Max3|43.00
Max2|77.00
Max3|18.00
Max1|97.00
Max1|87.00

我想使用 Left Join 并制作这样的输出:

Max1|Musterma|Muster Street|40.00
Max1|Musterma|Muster Street|97.00
Max1|Musterma|Muster Street|87.00
Max2|Musterma|Muster Street|77.00
Max3|Musterma|Muster Street|50.00
Max3|Musterma|Muster Street|43.00
Max3|Musterma|Muster Street|18.00
Max4|Musterma|Muster Street|
Max5|Musterma|Muster Street|

我得到的是这样的:

Max3|Musterma|Muster Street|50.00
Max1|Musterma|Muster Street|40.00
Max3|Musterma|Muster Street|43.00
Max2|Musterma|Muster Street|77.00
Max3|Musterma|Muster Street|18.00
Max1|Musterma|Muster Street|97.00
Max1|Musterma|Muster Street|87.00
Max4|Musterma|Muster Street|
Max5|Musterma|Muster Street|

我得到的内容是在第二个(右)表的条目位置之后排序的。

但我想让列表排序

  1. 在用户的第一个位置之后
  2. 在第二个钱的位置之后

谁能告诉我我还要写什么?

4

2 回答 2

1

在 SQL 的末尾添加一个order by子句。它看起来像这样:

order by Table1.Name, Table2.Money
于 2012-11-08T01:52:46.407 回答
0

您可以使用 order by 子句,如下所示:

select name
     , sir_name
     , address
     , money
from   table1
left join table2 on (...)
ORDER BY name, money

我只是猜到了您的表和列的名称,因为您没有提供它们=)

于 2012-11-08T01:57:07.990 回答