- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题之前已经讨论过,但没有一个答案能解决我的具体问题,因为我正在处理内部和外部选择中的不同 where 子句。该查询在 Sybase 下执行得很好,但在 SQL Server 下执行时会出现本文标题中的错误。查询比较复杂,但是查询的大致轮廓是:
select sum ( t.graduates -
( select sum ( t1.graduates )
from table as t1
where t1.id = t.id and t1.group_code not in ('total', 'others' ) ) )
from table as t
where t.group_code = 'total'
以下描述了我正在尝试解决的情况:
有没有办法使用派生表或联接重写它以获得相同的结果?
更新:我创建了 sample data and 3 solutions to my specific problem (2 受 sgeddes 影响)。我添加的一项涉及将相关子查询移动到 FROM 子句中的派生表。谢谢大家的帮助!
最佳答案
一种选择是将子查询放在LEFT JOIN
中:
select sum ( t.graduates ) - t1.summedGraduates
from table as t
left join
(
select sum ( graduates ) summedGraduates, id
from table
where group_code not in ('total', 'others' )
group by id
) t1 on t.id = t1.id
where t.group_code = 'total'
group by t1.summedGraduates
也许更好的选择是将 SUM
与 CASE
结合使用:
select sum(case when group_code = 'total' then graduates end) -
sum(case when group_code not in ('total','others') then graduates end)
from yourtable
关于SQL Server "cannot perform an aggregate function on an expression containing an aggregate or a subquery",但 Sybase 可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15751241/
有谁知道查询上次重建 sybase 索引的日期的方法吗? 最佳答案 这似乎是唯一的方法,索引的创建日期: select name, id, crdate from sysindexes where i
我搜索了一段时间,无法得到答案。 为什么这不起作用? 更改表 mytable ALTER COLUMN 价格翻倍 最佳答案 语法不正确,Sybase 中没有 DOUBLE 数据类型。 所以,你可以这样
我想返回所有表及其旁边的计数。最快的方法是什么? 我知道在 Oracle 中,您可以执行以下操作,但不确定 Sybase: declare n number; begin for rec in
在 sql server 2012 中我使用 USE myDatabase; GO SELECT * FROM sys.objects WHERE type = 'U'; 是否可以在 sy
我在 sybase 上遇到这个问题。 update tst_table set col1 = 'abc ' 结果将是 abc Sybase 将自动消除空格。但是我正在迁移,因此无法手动添加空格。 最
我在 sybase 上遇到了这个问题。 update tst_table set col1 = 'abc ' 结果将是 abc Sybase 会自动消除空格。但是我正在迁移,所以我无法手动添加空格。
我的要求是使用syscolumn 和systable 系统表。通过使用这两个表,返回特定模式中的特定表。但是 systable 持有来自 3 个不同模式的相同表名,如何获取具有所需模式的表名? tab
我有一个带有标识列的表。它有 100 行。我截断了表格。现在,如果我插入身份值为 101 等的新记录。有人可以告诉我如何将身份重置为零。 最佳答案 您需要的 SQL 是: sp_chgattribut
我有一个连接到 Sybase 数据库的数据源。我需要在连接到数据库后执行身份验证语句 (SET TEMPORARY OPTION CONNECTION_AUTHENTICATION='Company.
我正在使用带有 TSQL 的 Sybase DB。 我可以查看我的数据库中的所有自定义数据类型,但是我看不到它们所包含的底层 native 数据类型(INT、VARCHAR、CHAR、...)。 我使
当我点击以下查询时,我得到 1 行 SELECT * FROM servers WHERE Node='abc_deeh32q6610007' 但是,当我点击以下查询时,选择了 0 行 SELECT
Sybase 12.5 我在生产中有一个现有的表,需要更改它的 PK int 列,以便自动填充 - 创建表时,最好将 ID 列创建为标识。此 ID 列是多个其他表中的外键,因此不能选择删除该表并重新开
我曾在 SQL Server 数据库上工作过。现在我必须在 Sybase 数据库上工作(使用 Squirrel 客户端)。此查询不起作用: DECLARE @tableName VARCHAR(500
我正在尝试检索我的 sybase DB 的 DB 大小。但是我在任何地方都得到了这个命令来查看 DB 大小,“ sp_spaceused ”。但是这个命令显示了所有信息以及 DB 大小。 下面是输出,
很久以前,我发现 bcp 只是一个小 C 程序,它调用 sybase 客户端 api 的特殊位来将大量数据移入数据库。它以速度的名义欺骗和抢断并跳过检查限制。 太好了,我全力以赴。 在 sybase
我正在尝试通过 Rapid Sql 在 Sybase15 数据库上运行查询。我收到错误消息,例如 -- Number (103) Severity (15) State (207) Server (s
我将 Sybase.Data.AseClient.dll 导入到我的 C# 项目中以连接到 sybase 数据库并查询类似这样的内容 private DataSet query(string jjop
Sybase 有一种应用程序通信方式"context" data - 例如应用程序的最终用户名等。 - 数据库连接 session 。上下文数据基本上只是一组键值对,通过 set_appcontext
我需要从 Ruby 连接到一个相当古老的 Sybase 数据库。 我最终使用了 jRuby,只是因为我无法通过任何方式从 MRI 连接到 Sybase 来工作;如果有一种方法可以实际工作并且不疯狂地为
我有以下 Perl 脚本: use strict; use warnings; use DBI; my $db_connect = 'dbi:Sybase:server=10.2.2.2\CATDB;
我是一名优秀的程序员,十分优秀!