易截截图软件、单文件、免安装、纯绿色、仅160KB

求一SQL语句 - MS-SQL Server / 基础类

有表如下
a b c
001 收入 5000
001 费用 2000
001 合计 3000
002 收入 6000
002 费用 3000
002 合计 3000
003 收入 4000
003 费用 1000
003 合计 2000
...
合计=收入-费用
求一语句 查找出当b=收入时c字段不正确的记录


select 不正确记录=x.a from ta x join ta y on x.合计<>y.收入-y.费用 where x.b='收入'

SQL code:

select a,sum(case b when '收入' then c else -c end)
from your_table
group by a
having sum(case b when '收入' then c else -c end) <> 0



SQL code:

use PracticeDB
go
if exists (select 1 from sysobjects where name='tb_a')
drop table tb_a
go
create table tb_a (a varchar(10), b varchar(10),c numeric(10))
go
insert into tb_a
select '001', '收入' ,5000 union all
select '001', '费用' ,2000 union all
select '001', '合计' ,3000 union all
select '002', '收入' ,6000 union all
select '002', '费用' ,3000 union all
select '002', '合计' ,3000 union all
select '003', '收入' ,4000 union all
select '003', '费用' ,1000 union all
select '003', '合计' ,2000
合计=收入-费用
求一语句 查找出当b=收入时c字段不正确的记录


select * from tb_a

;with t
as
(
select a,sum(case b when '收入' then c else 0 end) [收入],


相关问答:

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

数据以xml格式返回 - MS-SQL Server / 应用实例

从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
   <folder state="unchecked&qu ......

sql - MS-SQL Server / 疑难问题

sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊

随便搞一D版吧,

迅雷第一个就可以用
2000,2005都这样

http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......

请教SQLSERVER的两个问题 - MS-SQL Server / 疑难问题

1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......

关于Sql的问题 - .NET技术 / ASP.NET

将一个查询语句赋给一个变量,如下:
DECLARE @STR NVARCHAR(MAX)
SET @STR='SELECT * from SALE_PROD'
怎么样才能执行它呢?
请高手,仁兄,侠姐帮帮忙啊


多谢,可以啦,高手啊

直接执行就行了

exec ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号