Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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) [ÊÕÈë],


Ïà¹ØÎÊ´ð£º

jspÁ´½Ósql2000µÄÒÉÎÊ£¿



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

ÇóÒ»¸öSQLÓï¾ä - MS-SQL Server / »ù´¡Àà

×Ö¶Î1,×Ö¶Î2.....×Ö¶ÎN,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
ÏëÒªµÄ½á¹ûÊÇ:
1,Na ......

Çóһʱ¼ä±È½ÏµÄSQL Ö¸Áî - MS-SQL Server / »ù´¡Àà

±íÊý¾Ý
COL1 COL2 COL2 COL4 COL5
----------------------------------------------------------------------------------------------
2010-05-05 00:00 ......

Ôõô°ÑMDFÊý¾Ýתµ½MySQL£¿ - MS-SQL Server / »ù´¡Àà

Ôõô°ÑMDFÊý¾Ýתµ½MySQL£¿
ÖÁÉٵø½¼Óµ½sqlserverÉÏ

¾ßÌåÔõôŪ°¡ ÎҵıÏÒµÉè¼ÆµÄÊý¾Ý¿âÊÇ´ÓÍøÉÏdownÏÂÀ´µÄ£¿£¿

Ä㻹²»ÈçÖ±½ÓÓÃsqlserverÄØ

º¯Êý¡¢´æ´¢¹ý³Ì¶¼µÃ¸ÄÁË¡£

sqlserverûÔõôÓùý¡£Ò²Ã»Óа²× ......

sqlÓï¾äÎÊÌâ - Java / Web ¿ª·¢

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»áÓÐ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ