用like
和 case when
表格
CREATE TABLE IF NOT EXISTS `docs` (
`id` int(6) unsigned NOT NULL,
`fileName` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `docs` (`id`, `fileName`) VALUES
('1', '111-1.pdf'),
('2', '111-2.pdf'),
('3', '99-1.pdf'),
('4', '99-2.pdf');
Select
select
CASE
WHEN a.fileName LIKE '%-1%' THEN 'A檔案'
WHEN a.fileName LIKE '%-2%' THEN 'B檔案'
ELSE '' END AS FileType
from `docs` as a;
簡單版(假設你的檔案只有PDF, *1.pdf 為A檔,*2.pdf 為b檔,upper硬轉大寫 )
SELECT CASE WHEN UPPER(RIGHT(FILENAME,5))='2.PDF' THEN 'B' ELSE 'A' END FILETYPE
FROM YOURTABLE
WHERE .......
畫蛇添足版(取檔名 . 的左邊的所有文字,再取最右邊那個字)
SELECT CASE WHEN RIGHT(LEFT(FILENAME,CHARINDEX('.',FILENAME)-1),1)='1' THEN 'A' ELSE 'B' END FILETYPE
FROM YOURTABLE
WHERE .....