bitsCN.com
mysql一些查询的解决方法
phpweb1.0基于php+mysql+smarty开发的企业解决方案,总体感觉简洁快速,适合小型企业的建站方案,也适合初学者学习。 之前发布过phpweb1.0的原始版本,仅提供大家交流和学习,但很多的爱好者提出了一些不足和好评,本不想继续开发1.0,因为2.0已经开发完毕而且构架与1.0完全不同,但是有些使用者喜欢这种简洁和简便,应大家的要求,美化和优化了一些不足之处。后台更加简洁美观。
0
Mysql 计算多个字段的值
原始数据库如下,所有的字段均为int 类型
+----+---------+---------+| id | column1 | column2 |+----+---------+---------+| 1 | 1 | 2 || 2 | 3 | 4 || 3 | 5 | 6 |+----+---------+---------+
希望的输出 result 的值为
column1 * column2+----+--------+| id | Result |+----+--------+| 1 | 2 || 2 | 12 || 3 | 30 |+----+--------+
使用的SQL 语句为
SELECT id, (column1 * column2) AS Result FROM table;
几点注意:
Mysql 支持常用的所有的算数运算符 +, -, *, /, %, p(整除), -(负号)
column1 * column2 这个表达式不能写成 'column1' * 'column2' 或 'column1 * column2'
Mysql 将多个字段值作为文本连接
还是上的数据库,这次希望输出为字符串形式的 column1 * column2,即:
+----+--------+| id | Result |+----+--------+| 1 | 1 * 2 || 2 | 3 * 4 || 3 | 5 * 6 |+----+--------+
使用如下的SQL 语句实现
SELECT id, CONCAT(column1, ' * ', column2) AS Result FROM table;
以后添加
bitsCN.com
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号