仅显示左值一次
我有两张桌子(客户,购买)。我通过 customerid 键加入了这两个表。这很好用。我的表格看起来像:
Cust_Name | Purchase $
Mike 2.00
Mike 3.00
Mike 4.00
Mike 10.00
Mike 30.00
但我想显示的是 Cust_name
仅一次(左表),并保持 Purchase $
的显示相同。所以它看起来像:
Cust_Name | Purchase $
Mike 2.00
3.00
4.00
10.00
30.00
我该如何去做呢?
I've got two tables (customer, purchase). I've joined these two tables via the customerid key. This works great. My table looks like:
Cust_Name | Purchase $
Mike 2.00
Mike 3.00
Mike 4.00
Mike 10.00
Mike 30.00
But what I would like to display is the Cust_name
only once (left table) and keep the display of Purchase $
the same. So it would look like:
Cust_Name | Purchase $
Mike 2.00
3.00
4.00
10.00
30.00
How do I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信你可以用纯 SQL
SELECT
查询轻松地做到这一点(我根本不愿意这么说)。如果您首先将其创建为临时表,则可以在该表上运行CURSOR
,但在我看来,这是一项更适合您的业务或表示层的任务。I don't believe you can do this easily (I loathe to say at all) with a pure SQL
SELECT
query. You could run aCURSOR
over the table if you create it as a temp table first but but IMO this is a task better suited for your business or presentation layers.这不是您应该在
SQL
查询中执行的操作。在关系数据库中,右侧有美元金额而左侧没有对应的值来关联它本质上是没有意义的。
任何像这样的美学变化都应该在您的应用程序或表示层中处理,而不是在数据库的逻辑中处理。
This is not something you should do in a
SQL
query.In a relational database, having a dollar amount on the right without a corresponding value on the left to tie it to is essentially meaningless.
Any aesthetic changes like this should be handled in your application or presentation layer, not in the logic of the database.