mysql 行转列问题
这几天所作的工作涉及到数据库行转列的问题
记录一下出现的错误,以免以后再犯
举网上最通俗的例子吧
Name Subject Result
张三 语文 80
张三 数学 90
张三 物理 85
李四 语文 85
李四 数学 92
李四 物理 82
想要的结果
姓名 语文 数学 物理
张三 80 90 85
李四 85 92 82
正确的写法
select name as 姓名,
max
(case when subject='语文' then result end) as 语文,
max
(case when subject='数学' then result end) as 数学,
max
(case when subject='物理' then result end) as 物理
from T1 group by
name
最开始写的时候不知道max
函数有什么用
而且也没有加
group by
最后的结果是
姓名 语文 数学 物理
张三 80
张三 90
张三 85
李四 85
李四 92
李四 82
发现结果不对,然后加了
group by语句
结果是
张三 80
李四 85
相关文档:
※ 关于MySQL的1067错误解决方法 ※
内容:
*************
1
安装MYSQL后更改了ROOT的密码后用
net startmysql
启动时我就遇到了这样的问题.使用以下命令后
c:\mysql\bin\mysqladmin-u root -p shutdown
再net start mysql就没有这个错误提示了!
*************
2
MySQL的1067错误
Q:我的Mysql碰到了 1 ......
下午看了一段PHP100的视频。
也算有点收获。
里面的一段自写的findall的SQL函数:
public function findall($table) {
$this->query("SELECT * from $table");
}
原来只是这么简单,刚还在思考。
使用了TAB键上面的顿号来修饰MYSQL里的字段名,如:
UPDATE tablename SET `fieldname`='values' wh ......
将Excel数据导入MySql
1.将选中的数据快儿拷贝到一个TXT文本文件中(记得把后面的空格消掉。。),假如存到“D:\data.txt”这个位置里。
2.根据要导入的数据快儿建立MySql数据库和表,然后进入命令提示符里使用命令
load data local infile 'D:\data.txt' into table exceltomysql fields terminated ......
Explain MySQL architecture
. - The front layer
takes care of network connections and security authentications, the
middle layer does the SQL query parsing, and then the query is handled
off to the storage engine. A storage engine could be either a default
one supp ......
在网站建设或者运营中,如果 MySQL server 是非常繁忙,可以开启 query cache 以加速回应时间,开启方法可以在 my.cnf 裡面加入以下项目: (Redhat 下面是 /etc/my.cnf;Debian 是在 etc/mysql
/my.cnf).
query_cache_size = 64M
query_cache_type = 1
query_cache_limit = 1048576
以上语法的设定里面, ......