sqlÓï¾ä - MS-SQL Server / »ù´¡Àà
Ò»±í
ÐÕÃû | 1 | 2 | 3 | 4 | 5 |¡£¡£¡£¡£¡£¡£
ÕÅÈý ʼ٠²¡¼Ù ʼ٠²¡¼Ù ²¡¼Ù¡£¡£¡£¡£¡£
ÀîËÄ »é¼Ù ³ö²î ³ö²î ³ö²î ³ö²î
ÈçºÎµÃ³ö
ÐÕÃû ʼ٠²¡¼Ù »é¼Þ ³ö²î¡£¡£¡£¡£
ÕÅÈý 2 3 0 0
ÀîËÄ 0 0 1 4
¼ÙÈçÐкÍÁеÄÄÚÈݶ¼Êǹ̶¨µÄ£¬¿ÉÒÔÓÃÒÔÏÂÓï¾ä£¬²»¹Ì¶¨ÇëʹÓö¯Ì¬SQL
SQL code:
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([ÐÕÃû] varchar(4),[1] varchar(4),[2] varchar(4),[3] varchar(4),[4] varchar(4),[5] varchar(4))
insert [tb]
select 'ÕÅÈý','ʼÙ','²¡¼Ù','ʼÙ','²¡¼Ù','²¡¼Ù' union all
select 'ÀîËÄ','»é¼Ù','³ö²î','³ö²î','³ö²î','³ö²î'
go
select ÐÕÃû,
sum(case when note ='ʼÙ' then 1 else 0 end) as [ʼÙ],
sum(case when note ='²¡¼Ù' then 1 else 0 end) as [²¡¼Ù],
sum(case when note ='»é¼Þ' then 1 else 0 end) as [»é¼Þ],
sum(case when note ='³ö²î' then 1 else 0 end) as [³ö²î]
from(
select [ÐÕÃû],[1] as note from tb
union all
select [ÐÕÃû],[2] from tb
union all
select [ÐÕÃû],[3] from tb
union all
select [ÐÕÃû],[4] from tb
union all
select [ÐÕÃû],[5] from tb
) t group by ÐÕÃû
/**
ÐÕÃû ʼ٠²¡¼Ù »é¼Þ ³ö²î
---- ----------- ----------- ----------- -----------
ÀîËÄ 0 0 0 4
ÕÅÈý 2 3 0 0
(2 ÐÐÊÜÓ°Ïì)
**/
¶¯Ì
Ïà¹ØÎÊ´ð£º
ͨ¹ýNAME×Ö¶ÎÌõ¼þ²éѯһ¸öÊý¾Ý±í£¬¼ÙÉèÎÒÓÐ100¸öÐÕÃû£¬ÓÐÒÔÏÂÁ½¸ö·½·¨£¬
·½·¨1£º
°Ñ100¸öName ×é³ÉÒ»¸öSQLÓï¾ä£¬±ÈÈç Select * from tmp_table where Name='ÕÅÈý' or Name ='ÀîËÄ' Or ...Or Name='µÚÒ»°Ù¸öÐÕÃû'
......
Ôõô°ÑMDFÊý¾Ýתµ½MySQL£¿
ÖÁÉٵø½¼Óµ½sqlserverÉÏ
¾ßÌåÔõôŪ°¡ ÎҵıÏÒµÉè¼ÆµÄÊý¾Ý¿âÊÇ´ÓÍøÉÏdownÏÂÀ´µÄ£¿£¿
Ä㻹²»ÈçÖ±½ÓÓÃsqlserverÄØ
º¯Êý¡¢´æ´¢¹ý³Ì¶¼µÃ¸ÄÁË¡£
sqlserverûÔõôÓùý¡£Ò²Ã»Óа²× ......
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Õ¾Àï ±¾ÉíÓÐ ......
A±í ÓÐÁ½¸ö×Ö¶Î
id ΨһÊý×ÖÓò
InfoTxt text ÀàÐÍ
ÎÒÏÖÔÚÒª°Ñ id ²»ÊÇ14 µÄËùÓÐ InfoTxt×ֶΠÎı¾ºóÃæ ¶¼¼ÓÉÏ 'aaa'
°´ÏÂÃæÖ´ÐÐÏÂÀ´ Ö»Óбí×îºóÒ»ÐмÓÉÏÁË 'aaa' ......