21,886
社区成员
发帖
与我相关
我的任务
分享
-- phpMyAdmin SQL Dump
-- version 2.6.0-pl3
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2010 年 01 月 19 日 10:46
-- 服务器版本: 5.0.22
-- PHP 版本: 5.2.5
--
-- 数据库: `aa`
--
-- --------------------------------------------------------
--
-- 表的结构 `test`
--
CREATE TABLE `test` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`a_money` decimal(10,2) default NULL,
`type` tinyint(1) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=5 ;
--
-- 导出表中的数据 `test`
--
INSERT INTO `test` VALUES (1, '猥琐强', 20.00, 1);
INSERT INTO `test` VALUES (2, '猥琐强', 30.00, 2);
INSERT INTO `test` VALUES (3, '帅哥', 40.00, 1);
INSERT INTO `test` VALUES (4, '帅哥', 50.00, 1);
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("select name,
sum(if(type=1,a_money,0)) as 借款金额,
sum(if(type=2,a_money,0)) as 报销金额
from test
GROUP BY name");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf ("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result);
?>
你自已改一下数据库的设置