Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2003, 12:21 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default can this be done?

need help.. urgent!

I need to write a select statement to get the following results.
I tried using joins, but it just takes all my cpu time, and takes forever to process.



TABLES:
-----------------
(about 500 records)
CREATE TABLE `A` (
  `ACCNT_CODE` varchar(50) default NULL,
  `TRANS_DATE` datetime default NULL,
  `AMOUNT` double default NULL,
  `TREFERENCE` varchar(50) default NULL,
  `OTHER_AMT` double default NULL,
  `TRANS_ID` int(11) NOT NULL auto_increment,
  KEY `TRANS_ID` (`TRANS_ID`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

(about 50000 records)
CREATE TABLE `B` (
  `ACCNT_CODE` varchar(255) default NULL,
  `ACCNT_NAME` varchar(255) default NULL,
  `AN_A2` varchar(255) default NULL,
  `BADFLAG` varchar(50) default 'N',
  `DATE_ACTION` datetime default '2001-01-19 00:00:00',
) TYPE=MyISAM;

(about 5000 records)
CREATE TABLE `C` (
  `CATEGORY` varchar(255) default NULL,
  `CODE` varchar(255) default NULL,
  `NAME` varchar(255) default NULL
) TYPE=MyISAM;
------------------------




RESULT NEEDED:
---------------------
ACCNT_CODE,

ACCNT_NAME,

TOTAL_AMOUNT,
SUM(A.AMOUNT) GROUP BY ACCNT_CODE,

OVERDUE_AMNT,
SUM(A.AMOUNT) WHERE TRANS_DATE > 'x' GROUP BY ACCNT_CODE

DATE_ACTION,

NAME,
C.CODE=B.AN_2 AND C.CATEGORY='x'
----------------------------------------------


WHERE A.ACCNT_CODE=B.ACCNT_CODE
GROUP BY ACCNT_CODE


Anyone has a solution?

Thanks
 
Old December 1st, 2003, 01:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you post the select statement that you tried???

-Vijay G
 
Old December 1st, 2003, 12:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, you might be better off if you created real indexes in your columns. You don't have ANY columns where a numeric (read: easily sorted and compared) value serves as a unique index into that column.

When you're combining three tables of up to 50000 rows per table, and you're performing all your comparisons in VARCHAR fields, you're wasting a LOT of space and requiring a LOT of computing.



Take care,

Nik
http://www.bigaction.org/









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.