SQL Server GROUP BY 和 FIRST
我有很多画廊里的物品。我有很多照片。图片在画廊里。
我想创建一个视图,在其中列出画廊以及画廊中第一张图片的一些属性。
类似于:
ALTER VIEW [foto].[gallery_with_picture]
AS
select
main.*
,FIRST(pics.[picture_id])
,FIRST(pics.[picture_width])
,FIRST(pics.[picture_height])
,FIRST(pics.[URLPart] as picture_url_part)
,FIRST(pics.[Extension] as picture_extension)
from
[v_gallery] main
left join [v_picture_recursive] pics on main.[foto_reference_picture_group_modeling_object/obj_id] = pics.woc_root
group by
main.*
order by
pics.[picture_id]
当然这不起作用,因为 SQL Server 没有可用的 FIRST 聚合函数。或者确实如此?
或者我应该使用 top1 进行内部选择,因为没有更简单的解决方案?
I have a lot of gallery objects. I have a lot of pictures. The pictures are in the galleries.
I want to create a view where I list the galleries and some properties of the first picture in the gallery.
Something like:
ALTER VIEW [foto].[gallery_with_picture]
AS
select
main.*
,FIRST(pics.[picture_id])
,FIRST(pics.[picture_width])
,FIRST(pics.[picture_height])
,FIRST(pics.[URLPart] as picture_url_part)
,FIRST(pics.[Extension] as picture_extension)
from
[v_gallery] main
left join [v_picture_recursive] pics on main.[foto_reference_picture_group_modeling_object/obj_id] = pics.woc_root
group by
main.*
order by
pics.[picture_id]
Of course this does not work as SQL Server has no working FIRST aggregate function for this. Or does it?
Or should I do an inner select with a top1 as there is no simpler solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种方法。
或者另一个
Here's one way.
Or another