这个MySQL视图的MS版本与GROUP BY? [英] MS Version of This MySQL View with GROUP BY?

查看:113
本文介绍了这个MySQL视图的MS版本与GROUP BY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被证明可以轻松地从多个表中创建一个视图,GROUPING BY xception的真棒答案中的一个表的id: CREATE VIEW WHERE SELECTID = VIEWROWID



有没有办法在MS中做到这一点?在任何地方,我读过的都是不,但没有一页给出了替代方案。

我不需要计数或任何东西,只需要多个表中的多列GROUPed BY(?)在一张桌子上放一列。



非常感谢!

示例



感谢您的回复。



对于视图的SELECT:

  SELECT dbo.table1.column1 AS table1column1,
dbo.table1.column2 AS table1column2,
dbo.table2.column1 AS table2column1,
dbo.table2.column2 AS table2column2
FROM table1,table2
WHERE table2.column1 = table1.column1
GROUP BY table1.column1


  SELECT dbo.table1.column1 AS table1column1,
min(dbo.table1.column2)AS table1column2,
min(dbo.table2.column1)AS table2column1,
min(dbo.table2.column2)AS table2column2
FROM table1,table2
WHERE table2.column1 = table1.column1
GROUP BY table1.column1

我强烈建议您阅读此博客文章 http://rpbouman.blogspot.de/2007/05/debunking-group-by-myths.html 了解MySQL正在做什么(错误)

I was shown the ease that one can make a view from multiple tables, GROUPing BY an id of one of the tables in xception's awesome answer here: CREATE VIEW WHERE SELECTid = VIEWrowID

Is there any way to do that in MS? Everywhere, I've read says "no", but no page gives an alternative.

I don't need the counts or anything, just multiple columns from multiple tables GROUPed BY(?) a single column on one table.

Thanks a lot in advance!

EXAMPLE

Thank-you for responding.

For the view's SELECT:

SELECT dbo.table1.column1 AS table1column1,
       dbo.table1.column2 AS table1column2,
       dbo.table2.column1 AS table2column1,
       dbo.table2.column2 AS table2column2
FROM table1, table2
WHERE table2.column1 = table1.column1
GROUP BY table1.column1

解决方案

As MySQL simply picks a random value from the non-grouped columns, the following should do it:

SELECT dbo.table1.column1 AS table1column1,
       min(dbo.table1.column2) AS table1column2,
       min(dbo.table2.column1) AS table2column1,
       min(dbo.table2.column2) AS table2column2
FROM table1, table2
WHERE table2.column1 = table1.column1
GROUP BY table1.column1

I highly recommend you read this blog posting http://rpbouman.blogspot.de/2007/05/debunking-group-by-myths.html to understand what MySQL is doing (wrong)

这篇关于这个MySQL视图的MS版本与GROUP BY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆