Solved

FoxPro SQL

Posted on 2012-04-09
5
424 Views
Last Modified: 2012-04-10
I would like someone to help me by writing a query in FoxPro
Please see attached spreadsheet where all is explained
Many thanks
R

ps........ filename (sales) should also be selected as part of the query
FoxPro--SQL.xlsx
0
Comment
Question by:racepro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 37822964
This sounds like a home work...
What date should be displayed in the result? Your Excel file shows min date, so the following quesry will do the same calculation:
SELECT MIN(dob) AS dob, COUNT(*) AS dob_count, SUM(buyprice) AS buyprice, SUM(sellprice) AS sellprice, ;
    SUM(sellprice-buyprice) AS p_l,  100.00*SUM(sellprice-buyprice)/SUM(buyprice) AS p_l_perc, ;
   SUM(held) AS held, SUM(sold) AS sold, 100.00*SUM(sold)/SUM(held) AS sold_perc ;
 FROM sales ;
 WHERE dob BETWEEN DATE(1954, 4, 1) AND DATE(1956, 4, 24) ;
   AND gender = "F" AND age BETWEEN 20 AND 44 ;
   AND religion = "C" AND location = "Germany"

Open in new window

0
 
LVL 42

Expert Comment

by:pcelba
ID: 37822987
You should clarify the date range (DOB BETWEEN 1-APR AND 24 APR) because date contains the year also. The last requirement to select the filename as a part of the query also does not sound so meaningfull but you may add a new column containing DBF() or ALIAS() function to the query.
0
 

Author Comment

by:racepro
ID: 37831198
Hi pcelba

Thanks for the formula.
BTW it was not 'homework'  At 66 I must be the oldest student
on here LOL
Can you advise how to reduce to a one line rather than group by (fieldname).?
Thanks
0
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 37831220
66 isn't so much. 82 old years programmer started with VFP 9 last year. You may look at his work: http://www.dealmaster.com/

But back to your question. To reduce the SQL command result to one line without GROUP BY needs aggregate functions in all expressions. So if you need some constant field on output then you may use MIN() or MAX() function as it is done for dob column.
0
 

Author Closing Comment

by:racepro
ID: 37831225
Thanks pcelba
I don't feel so old after all.!!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question