MySqlTalk.com  

Go Back   MySqlTalk.com > MySQL > SQL syntax
User Name
Password
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread
Old 02-21-2006, 07:22 AM   #1
konja
Junior Member
 
Join Date: Feb 2006
Posts: 3 konja is on a distinguished road
Help Needed !!

Trying to run a report with following features:
-on same report line data from two records in the same table
-table structure
CUST YEAR MONTH SALES ...
1234 2006 01 1000
1234 2006 02 1200
... ..... ....

1234 2005 01 800
1234 2005 02 600
... ..... ....

-report structure for the monh of 01:

CUST YEAR MONTH SALES SALES2005
1234 2006 01 1000 800
....

I'm newbi and tried hard but without success so far...
Help needed!
konja
konja is offline   Fork this post Reply With Quote
Old 02-21-2006, 12:22 PM   #2
Azkaban
Senior Member
 
Join Date: Jul 2004
Posts: 167 Azkaban is on a distinguished road
Re: Help Needed !!

Can you explain your question better?

You probably can solve this with a self join.
__________________
** Most misspellings intentional to combat spaham filterz**
Azkaban is offline   Fork this post Reply With Quote
Old 02-22-2006, 02:47 AM   #3
konja
Junior Member
 
Join Date: Feb 2006
Posts: 3 konja is on a distinguished road
Smile Re: Help Needed !!

mysql db table look much like this:
-only one table, only one "record" per CUST,YEAR,MONTH

CUST YEAR MONTH SALES ...
1234 2006 01 1000
1234 2006 02 1100
1234 2006 03 1200
1234 2006 04 1100
1234 2006 05 1000
1234 2006 06 1400
... ..... ....

1234 2005 01 800
1234 2005 02 600
1234 2005 03 1600
1234 2005 04 700
1234 2005 05 900
... ..... ....

1244 2006 01 500
.... ...... .....



-report structure for the monh of 01:

CUST YEAR MONTH SALES SALES2005
1234 2006 01 1000 800
....

The point is to get into the report: sales of the current period as well
as sales of the period one year ago.
I think this should be rather easy if one has experience which
I don't yet have. Thank you very much for helping.
konja
konja is offline   Fork this post Reply With Quote
Old 02-23-2006, 11:28 AM   #4
Azkaban
Senior Member
 
Join Date: Jul 2004
Posts: 167 Azkaban is on a distinguished road
Re: Help Needed !!

If you want to programmatically get the previous year into the report without sending a SELECT statement specifying the actual year/month, you probably want to look at the documentation about time and date handling. But you seem to be hardcoding dates into the data so maybe you can get away without it.

Let's start with a simple Select statement and maybe work from there.

SELECT sales
FROM mytablename
WHERE
CUST = '1234'
AND MONTH='01'
AND (YEAR='2006' OR YEAR='2005')
ORDER BY year DESC

I may have the syntax slightly off, and depending what programming language you are using, you may have different ways to access the current and previous year, whereas I hard coded it here as 2006 and 2005.

Try that out and see if it works.
__________________
** Most misspellings intentional to combat spaham filterz**
Azkaban is offline   Fork this post Reply With Quote
Old 02-23-2006, 12:28 PM   #5
konja
Junior Member
 
Join Date: Feb 2006
Posts: 3 konja is on a distinguished road
Re: Help Needed !!

Hi!
Thank you for your kind reply. One point I forgot to tell was that
I want to have on the report on the same ROW both 2006 and 2005
numbers!
However I found the solution myself after trying hard with
"inner join". Nice having you guys helping, Looking forward
later on coming back if some problem come ahead.
konja / Finland
konja is offline   Fork this post Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed on setting up a database! AKKI Installation 1 07-07-2005 03:53 PM
Recursive Help Needed 4.0.22 MySQL Vmusic SQL syntax 3 12-16-2004 10:10 AM
Mysql with automatic import scheduling feature needed lousueyesh Utilities 0 11-26-2004 02:07 PM



All times are GMT -4. The time now is 06:56 AM.



Powered by: vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Google
  Web http://www.mysqltalk.com
DISCLAIMERS:
1. We have no commercial interest in this site.
Banner Ads and Subscriptions will only be used to help pay for hosting and maintenance costs.
2. MySQLTalk.com is NOT affiliated with MySQL AB in any way.
3. MySQLTalk.com is NOT endorsed by MySQL AB in any way.
4. Please do not post any content that is harmful to MySQL or MySQL AB, meaning no misleading or obsolete information will be tolerated.
Well-founded constructive criticism meant to help the community is permitted.
5. This website is founded with the goal of improving the MySQL community.
We not only tolerate newbies, we encourage them.
Please do not ask newbies to "read the manual".