caseÓï¾äÔÚSQLÖеÄʹÓ÷½·¨
Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
WHEN '1' THEN 'ÄÐ'
WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
WHEN sex = '2' THEN 'Å®'
ELSE 'ÆäËû' END
ÕâÁ½ÖÖ·½Ê½£¬¿ÉÒÔʵÏÖÏàͬµÄ¹¦ÄÜ¡£¼òµ¥Caseº¯ÊýµÄд·¨Ïà¶Ô±È½Ï¼ò½à£¬µ«ÊǺÍCaseËÑË÷º¯ÊýÏà±È£¬¹¦ÄÜ·½Ãæ»áÓÐЩÏÞÖÆ£¬±ÈÈçдÅжÏʽ¡£
»¹ÓÐÒ»¸öÐèҪעÒâµÄÎÊÌ⣬Caseº¯ÊýÖ»·µ»ØµÚÒ»¸ö·ûºÏÌõ¼þµÄÖµ£¬Ê£ÏµÄCase²¿·Ö½«»á±»×Ô¶¯ºöÂÔ¡£
--±ÈÈç˵£¬ÏÂÃæÕâ¶ÎSQL£¬ÄãÓÀÔ¶ÎÞ·¨µÃµ½“µÚ¶þÀà”Õâ¸ö½á¹û
CASE WHEN col_1 IN ( 'a', 'b') THEN 'µÚÒ»Àà'
WHEN col_1 IN ('a') THEN 'µÚ¶þÀà'
ELSE'ÆäËû' END
ÏÂÃæÎÒÃÇÀ´¿´Ò»Ï£¬Ê¹ÓÃCaseº¯Êý¶¼ÄÜ×öЩʲôÊÂÇé¡£
Ò»£¬ÒÑÖªÊý¾Ý°´ÕÕÁíÍâÒ»ÖÖ·½Ê½½øÐзÖ×飬·ÖÎö¡£
ÓÐÈçÏÂÊý¾Ý:(ΪÁË¿´µÃ¸üÇå³þ£¬ÎÒ²¢Ã»ÓÐʹÓùú¼Ò´úÂ룬¶øÊÇÖ±½ÓÓùú¼ÒÃû×÷ΪPrimary Key)
¹ú¼Ò£¨country£©
ÈË¿Ú£¨population£©
Öйú
600
ÃÀ¹ú
100
¼ÓÄôó
100
Ó¢¹ú
200
·¨¹ú
300
ÈÕ±¾
250
µÂ¹ú
200
Ä«Î÷¸ç
50
Ó¡¶È
250
¸ù¾ÝÕâ¸ö¹ú¼ÒÈË¿ÚÊý¾Ý£¬Í³¼ÆÑÇÖ޺ͱ±ÃÀÖÞµÄÈË¿ÚÊýÁ¿¡£Ó¦¸ÃµÃµ½ÏÂÃæÕâ¸ö½á¹û¡£
ÖÞ
ÈË¿Ú
ÑÇÖÞ
1100
±±ÃÀÖÞ
250
ÆäËû
700
ÏëÒª½â¾öÕâ¸öÎÊÌ⣬Äã»áÔõô×ö£¿Éú³ÉÒ»¸ö´øÓÐÖÞCodeµÄView£¬ÊÇÒ»¸ö½â¾ö·½·¨£¬µ«ÊÇÕâÑùºÜÄѶ¯Ì¬µÄ¸Ä±äͳ¼ÆµÄ·½Ê½¡£
Èç¹ûʹÓÃCaseº¯Êý£¬SQL´úÂëÈçÏÂ:
SELECT SUM(population),
CASE country
WHEN 'Öйú' THEN 'ÑÇÖÞ'
WHEN 'Ó¡¶È' THEN 'ÑÇÖÞ'
WHEN 'ÈÕ±¾' THEN 'ÑÇÖÞ'
WHEN 'ÃÀ¹ú' THEN '±±ÃÀÖÞ'
WHEN '¼ÓÄôó' THEN '±±ÃÀÖÞ'
WHEN 'Ä«Î÷¸ç' THEN '±±ÃÀÖÞ'
ELSE 'ÆäËû' END
from Table_A
GROUP BY CASE country
WHEN 'Öйú' THEN 'ÑÇÖÞ'
WHEN 'Ó¡¶È' THEN 'ÑÇÖÞ'
WHEN 'ÈÕ±¾' THEN 'ÑÇÖÞ'
WHEN 'ÃÀ¹ú' THEN '±±ÃÀÖÞ'
WHEN '¼ÓÄôó' THEN '±±ÃÀÖÞ'
WHEN 'Ä«Î÷¸ç' THEN '±±ÃÀÖÞ'
ELSE 'ÆäËû' END;
ͬÑùµÄ£¬ÎÒÃÇÒ²¿ÉÒÔÓÃÕâ¸ö·½·¨À´ÅжϹ¤×ʵĵȼ¶£¬²¢Í³¼ÆÿһµÈ¼¶µÄÈËÊý¡£SQL´úÂëÈçÏ£»
SE
Ïà¹ØÎĵµ£º
1¡£°æ±¾£ºSql2008/2005
2¡£Ä¿µÄ£ºµ¼³öÖ¸¶¨µÄ±íÖÐËùÓÐÊý¾Ý£¬µ¼³ö¸ñʽΪ insert Óï¾ä
3¡£¾ßÌå²Ù×÷£º
1£©ÕÒµ½ÐèÒªµ¼³öµÄÊý¾Ý¿â£¬ÓÒ¼ü²Ëµ¥£¬ÈÎÎñ--¡µÉú³É½Å±¾
2£©½øÈëÏòµ¼£¬Ò»Â·ÏÂÒ»²½£¬×¢ÒâÑ¡ÔñÉú³É½Å±¾Ñ¡ÏîµÄʱºò£¬½«“±àдÊý¾ÝµÄ½Å±¾”ÉèÖÃΪ“True”¼´¿É
3£©±£´æÉú³ÉµÄSqlÎļþ ......
--Ê¡¼¶ Provincial
--³ÇÊÐ City
create table Provincial(pid int,Provincial varchar(50),primary key (pid))
insert into Provincial values(1,'±±¾©ÊÐ')
insert into Provincial values(2,'Ìì½òÊÐ')
insert into Provincial values(3,'ÉϺ£ÊÐ')
insert into Provincial values(4,'Ö ......
SQL Server 2008 Áª»ú´ÔÊ飨2009 Äê 7 Ô£©
ÍÚ¾òÄ£ÐÍ£¨Analysis Services - Êý¾ÝÍÚ¾ò£©
±¾½Ú½éÉÜÁËÊý¾ÝÍÚ¾òÄ£Ð͵Ļù±¾Ìåϵ½á¹¹£¬¸ÅÊöÁËÊý¾ÝÍÚ¾òÄ£Ð͵ÄÊôÐÔ£¬²¢ËµÃ÷ÁË´´½¨ºÍ´¦ÀíÍÚ¾òÄ£Ð͵ķ½Ê½¡£
Mining Model Architecture
Defining Mining Models
Mining Model Properties
Mining Model Columns
Processing Min ......
//±¾³ÌÐòÁ¬½ÓµÄÊÇsql server 2005£¬ÓëÁ¬½Ósql server 2000Óе㲻ͬ£ºdriverNameºÍURL¶¼²»Í¬
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class create{
public void getConnection() th ......
--default-character-set=utf8 ÓëÐÞ¸ÄsqlÎļþ¼ÓÈ룺SET NAMES 'utf8';
µ¼Èë½Å±¾Ê±£¬SET NAMES 'xxx' £¬xxxÓ¦¸ÃºÍsql½Å±¾ÎļþµÄʵ¼Ê±àÂëÒ»Ö£¬Èç¹ûÄãÉèÖõÄʱutf-8 £¬ÄÇôÇëÈ·ÈÏÄãµÄsql½Å±¾Îļþʱutf-8±£´æµÄ:
iconv -f UTF-8 xxx.sql
Èç¹ûÏÔʾÕý³££¬ÄÇôÕâÒ»²½¾ÍOKÁË
ÁíÍâ×¢ÒâÄãµÄ½Å±¾ÀÓÐûÓиø¿â±íÉèÖ ......