求一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) [收入],
相关问答:
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊
随便搞一D版吧,
迅雷第一个就可以用
2000,2005都这样
http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......
select o_customer,o_price from orders having o_price >=avg(o_price)
select o_customer,o_price from orders where o_price >=(select avg(o_price) from orders)
我感觉没有区别啊,怎么在mysql会有 ......
SQL code:
rs.open "select * from guide where city_name='北京' order by pai desc",conn,1,1
do while not rs.eof or rs.bof
。。
。。
。。
rs.movenext
loop
这个sql语句在wap站里 本身有 ......