一个字段多个值如何查询

解决方案 »

  1.   

    where  col=1 or col=2 or col=3
      

  2.   

    详细说明
    多个值:f1内容 1,2,3,4
    or
    f1=1 or f1=2
      

  3.   

    参考 FIND_IN_SET OR INSTR()函数
      

  4.   

    select * from table1
    where find_in_set(1,col)
      

  5.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  6.   

    -- phpMyAdmin SQL Dump
    -- version 2.11.4
    -- http://www.phpmyadmin.net
    --
    -- 主机: localhost
    -- 生成日期: 2011 年 04 月 16 日 03:57
    -- 服务器版本: 5.0.51
    -- PHP 版本: 5.2.5SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";--
    -- 数据库: `zhongliang`
    ---- ----------------------------------------------------------
    -- 表的结构 `zl_attribute`
    --CREATE TABLE IF NOT EXISTS `zl_attribute` (
      `attr_id` smallint(5) unsigned NOT NULL auto_increment,
      `cat_id` smallint(5) unsigned NOT NULL default '0',
      `attr_name` varchar(60) NOT NULL default '',
      `attr_input_type` tinyint(1) unsigned NOT NULL default '1',
      `attr_type` tinyint(1) unsigned NOT NULL default '1',
      `attr_values` text NOT NULL,
      `attr_index` tinyint(1) unsigned NOT NULL default '0',
      `sort_order` tinyint(3) unsigned NOT NULL default '0',
      `is_linked` tinyint(1) unsigned NOT NULL default '0',
      `attr_group` tinyint(1) unsigned NOT NULL default '0',
      PRIMARY KEY  (`attr_id`),
      KEY `cat_id` (`cat_id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=216 ;--
    -- 导出表中的数据 `zl_attribute`
    --INSERT INTO `zl_attribute` (`attr_id`, `cat_id`, `attr_name`, `attr_input_type`, `attr_type`, `attr_values`, `attr_index`, `sort_order`, `is_linked`, `attr_group`) VALUES
    (213, 9, '场合选酒', 1, 0, '聚会用\r\n约会用\r\n自饮用\r\n商务用\r\n婚宴用\r\n送礼用\r\n', 1, 0, 1, 0),
    (214, 9, '国家', 1, 0, '法国\r\n意大利\r\n澳大利亚\r\n德国\r\n美国\r\n西班牙\r\n智利\r\n新西兰\r\n阿根廷', 1, 0, 1, 0),
    (215, 9, '葡萄品种', 1, 0, '赤霞珠\r\n梅鹿辄\r\n霞多丽\r\n雷司令', 1, 0, 1, 0);
      

  7.   

    不知道你说的是不是这个意思?mysql> select  attr_name from zl_attribute where attr_values LIKE '%约会用%' \G;*************************** 1. row ***************************
    attr_name: 场合选酒
    1 row in set (0.00 sec)
      

  8.   


    你说的是这个意思?mysql> select attr_name,replace(attr_values,'\r\n',',') from zl_attribute where
    attr_values LIKE '%约会用%' \G;
    *************************** 1. row ***************************
                          attr_name: 场合选酒
    replace(attr_values,'\r\n',','): 聚会用,约会用,自饮用,商务用,婚宴用,送礼用,
    1 row in set (0.00 sec)
      

  9.   

    select * from zl_attribute
    where attr_values  like '%约会用%'
      

  10.   

    SELECT * FROM `zl_attribute` a1 WHERE INSTR(a1.attr_values,'约会用')
    or
    SELECT * FROM `zl_attribute` a1 WHERE a1.attr_values LIKE '%约会用%';