现在有一个表,表中的信息不是一次全部填写完的,所以想问一下,能不能在判断表中的某个字段是否为空之后决定是否关联其他表,如果为空则不不与其他表关联,如果不为空则与其他视图关联!
解决方案 »
- 希望大家看看这条语句如何优化!
- mysql外键设置问题,触发事件ON DELETE 如何设置为SET DEFAULT
- mysql 如何用SQL返回一个值,并用这个值进行查询???
- Mysql中tuncate中一个奇怪的问题
- 数据库类型转换!?
- 问个PostgreSql的问题,希望高人指点啊。。。。。。
- 关于mysql的安装问题高分相送
- [提问]如何在MYSQL下建立新的数据库
- MYSQL很简单的问题
- mysql中innodb和MyISAM引擎差距在哪里,分别适合在什么场景使用
- 怎样转换一个IP地址格式的字符串?
- com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式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)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
(
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 为空时对应的列显示为空
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楼主,你的语句自己有试过吧?能执行吗? 建议不要乱贴无法使用的东西,浪费别人的时间的同时也浪费自己的时间。
-> 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>