且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查询以逗号分隔的值列表

更新时间:2023-01-16 16:52:31

我完全同意您真的应该修复您的表格结构的意见.但是,如果您暂时需要一个丑陋的 hack,您可能会像这样:

I fully agree with the comments that you really should fix your table structure. However, if you need an ugly hack for the time being you might get away with something like this:

SELECT
    [Name],
    IIf(Skillz LIKE "*,C,*",1,0) AS C,
    IIf(Skillz LIKE "*,Python,*",1,0) AS Python,
    IIf(Skillz LIKE "*,CSS,*",1,0) AS CSS
FROM
    (
        SELECT 
            [Name],
            "," & Skills & "," AS Skillz
        FROM tblSkills
    )

诀窍是在技能列的开头和结尾处粘贴一个逗号,这样在每种情况下,您只需搜索诸如 "*,C,*" 之类的内容而不是 "C,*" 或 "*,C,*" 或 "*,C".

The trick is to glue a comma onto the beginning and the end of the Skills column so in each case you only search for something like "*,C,*" instead of "C,*" Or "*,C,*" Or "*,C".

此外,请注意有趣的字符",以防它们混淆 LIKE 运算符或产生麻烦的列名称.

Also, watch out for "funny characters" in case they confuse the LIKE operator or produce troublesome column names.