解决方案 »
- mysql是否有像ms sql server 那样的事件查看器
- 数据库不兼容问题
- mysql中,这样的语句怎么写? 即如果某表中没有字段ID(主键)的值为10的记录,则插入一条ID值为10的记录,否则什么都不做? 怎么写语句?
- mysql能够访问ACCESS数据库吗,就是以MDB结尾的数据库
- 关于 MYSQL存储过程
- MySql创建视图出现错误:1060 duplicate column name“sort_id",请问如何解决啊?
- mysql中hql语句的update提交问题
- POSTGRES数据库如何实现增量备份???
- mysql数据库移植的问题。
- mysql自动重启,大概半天时间就自动重启了
- sql 字段记录里有中文和英文,数字数据我怎么查非英文的数据
- 数据复制到临时表的问题
-> from ((select distinct user_id from choice_result) a ,choice_option b)
-> left join choice_result c on a.user_id=c.user_id and b.option_id=c.option_id
-> order by 1,2;
+---------+-----------+---------------+
| user_id | option_id | option_result |
+---------+-----------+---------------+
| 1001 | 2010 | 1 |
| 1001 | 2011 | NULL |
| 1001 | 2012 | NULL |
| 1001 | 3010 | 1 |
| 1001 | 3011 | NULL |
| 1001 | 4010 | 提高服务水平 |
| 2001 | 2010 | NULL |
| 2001 | 2011 | NULL |
| 2001 | 2012 | 朋友介绍 |
| 2001 | 3010 | NULL |
| 2001 | 3011 | NULL |
| 2001 | 4010 | 提高产品质量 |
+---------+-----------+---------------+
12 rows in set (0.00 sec)mysql>
自己写的时候就没有思路。mysql> select a.user_name,b.option_name,if(c.option_result=b.option_id,1,c.option_result) as option_result from
-> ((select distinct user_id,user_name from choice_result) a,choice_option b)
-> left join choice_result c on a.user_id=c.user_id and b.option_id=c.option_id order by 1,2;
+-----------+-------------+---------------+
| user_name | option_name | option_result |
+-----------+-------------+---------------+
| 张三 | 上网了解 | 1 |
| 张三 | 产品质量好 | NULL |
| 张三 | 其他 | NULL |
| 张三 | 建议: | 提高服务水平 |
| 张三 | 性价比高 | 1 |
| 张三 | 报纸杂志 | NULL |
| 李四 | 上网了解 | NULL |
| 李四 | 产品质量好 | NULL |
| 李四 | 其他 | 朋友介绍 |
| 李四 | 建议: | 提高产品质量 |
| 李四 | 性价比高 | NULL |
| 李四 | 报纸杂志 | NULL |
+-----------+-------------+---------------+
12 rows in set (0.01 sec)