SQL 大小比较

发布于 2024-08-14 00:48:48 字数 976 浏览 1 评论 0原文

我有一个数据库,我在其中检查大小,因为客户端可能只使用一定量的空间,并且它们可能只有一定数量的“页面”,我也将其放入数据库中。

我有以下 sql 查询:

SELECT table_schema "Servers",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;

这将返回一个包含我需要的信息的表。不过,我想添加 3 列来显示每个用户的使用量。首先我尝试这样:

SELECT table_schema "Servers",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB",
property_value "MaxWebhotelSize"
FROM information_schema.TABLES, properties
WHERE property_key LIKE 'MaxWEbhotelSize'
GROUP BY table_schema
UNION
SELECT property_value "MaxPages"
FROM properties
WHERE property_key LIKE 'MaxPages';

这应该添加我需要的两个列。如果我省略了从 union 到 down 的所有内容,它会很好地工作,并将有关最大网络酒店大小的信息添加到表中,但是当我尝试添加另一列时,我会收到一条错误消息,指出“所使用的 SELECT 语句具有不同的列数”。我尝试了一些其他方法,但似乎无法找到获得正确结果的好方法。我对 SQL 很陌生,如果这是一个愚蠢的问题,我很抱歉。

I have a database where I check on the size, because clients may only use a certain amount of space, aswell as they may only have a certain number of 'pages', which I put in the db aswell.

I have the following sql query:

SELECT table_schema "Servers",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;

This returns a table with the information I need. However, I would like to add 3 coloumns that also show how much each user is using. First I tried like this:

SELECT table_schema "Servers",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB",
property_value "MaxWebhotelSize"
FROM information_schema.TABLES, properties
WHERE property_key LIKE 'MaxWEbhotelSize'
GROUP BY table_schema
UNION
SELECT property_value "MaxPages"
FROM properties
WHERE property_key LIKE 'MaxPages';

This should take add two of the coloumns that I need. If I leave out everything from union and down it works well and adds information about maximum webhotel size to the table, but when I try to add another coloumn I get an error saying "The used SELECT statements have a different number of columns". I tried some other ways around it, but can't seem to figure out a good way where I get the right results. I'm quite new to SQL, sorry if this is a stupid question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗笺 2024-08-21 00:48:49

在联合查询中,列数应该相等。

因此,如果联合查询的第一部分有 3 列,第二部分也应该有 3 列。

在您的示例中,第二部分中只有 1 列。请在另外两列中指定您的需求,我们也许可以协助您进行查询。

In a union query, the number of columns should be equal.

So, if you have 3 columns in the first section of your union query, you should also have 3 columns in the second.

In your example, you only have 1 column in the second section. Please specify what you require in the additional 2 columns, and we might be able to assist with the query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文