[RESOLVED] Select sum(d),sum(k) from deposit group by sendernumber;
I am sorry if this is not the right category to post.
A Deposit tabel having structure like this;
CREATE TABLE IF NOT EXISTS `deposit` (
`id` smallint(5) NOT NULL auto_increment,
`SenderNumber` varchar(15) NOT NULL,
`D` int(10) NOT NULL,
`K` int(10) NOT NULL,
`text` varchar(160) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
INSERT INTO `smsd`.`deposit` (`id`, `SenderNumber`, `D`, `K`, `text`) VALUES (NULL,
'+6285668878868', '100000', '0', '+6285668878868+100');
INSERT INTO `smsd`.`deposit` (`id`, `SenderNumber`, `D`, `K`, `text`) VALUES (NULL,
'+6285668878868', '100000', '0', '+6285668878868+100');
INSERT INTO `smsd`.`deposit` (`id`, `SenderNumber`, `D`, `K`, `text`) VALUES (NULL,
'+6285668878868', '0', '10000', '+6285668878868+100');
INSERT INTO `smsd`.`deposit` (`id`, `SenderNumber`, `D`, `K`, `text`) VALUES (NULL,
'+6285668878868', '0', '10000', '+6285668878868+100');
INSERT INTO `smsd`.`deposit` (`id`, `SenderNumber`, `D`, `K`, `text`) VALUES (NULL,
'+6285668878868', '0', '10000', '+6285668878868+100');
when I use sum like following line in phpmyadmin it woring fine
SELECT SUM(D),SUM(K) FROM DEPOSIT GROUP BY SENDERNUMBER;
SELECT SUM(D),SUM(K) FROM DEPOSIT WHERE SENDERNUMBER=+6285668878868;
I have problem on calculation and to
add another collum call 'balance' as a variabel of sum(D) - sum(K).
that is;D - K = balance
anyone help me to solve this problem?
thanks a lot for your advise
kind Regards,
Re: Select sum(d),sum(k) from deposit group by sendernumber;
Sum(d) - Sum(k) As `Balance`
That's about as simple as it gets.
-tg
Re: Select sum(d),sum(k) from deposit group by sendernumber;
thanks techgnome it is work fine.