现在有一个表,表中的信息不是一次全部填写完的,所以想问一下,能不能在判断表中的某个字段是否为空之后决定是否关联其他表,如果为空则不不与其他表关联,如果不为空则与其他视图关联!

解决方案 »

  1.   

    应该可以,但建议你详细说明你的需求。
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式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)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  2.   

    create table test1
    (
    id1 varchar(10),
    name1 varchar(20),
    name2 varchar(20)
    )
    insert into test1 select '01',空,‘b1’
    insert into test1 select '02','a2','b2'create table test2
    (
    id2 varchar(10),
    name3 varchar(20),
    name4 varchar(20))
    insert into test2 select '01','a1','c1'
    insert into test2 select '04','a2','c2'希望建立视图得到
    01 空 b1 空
    02 a2 b2 c2
    就是想在test1的name1不为空时与test2关联 得到name4 为空时对应的列显示为空
      

  3.   

    mysql> insert into test1 select '01',空,‘b1’;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use near '空,‘
    b1’' at line 1楼主,你的语句自己有试过吧?能执行吗? 建议不要乱贴无法使用的东西,浪费别人的时间的同时也浪费自己的时间。
      

  4.   

    mysql> Select id1,name3,name2,name4
        -> From test1 left join test2 on test1. Name1= test2. name3
        -> ;
    +------+-------+-------+-------+
    | id1  | name3 | name2 | name4 |
    +------+-------+-------+-------+
    | 01   | NULL  | b1    | NULL  |
    | 02   | a2    | b2    | c2    |
    +------+-------+-------+-------+
    2 rows in set (0.00 sec)mysql>