Solved

FoxPro SQL

Posted on 2012-04-09
5
422 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
  • 3
  • 2
5 Comments
 
LVL 41

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 41

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 41

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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