General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 19th, 2005, 01:13 PM
DesertDomer DesertDomer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 DesertDomer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Subquery in Columns/Fields

I tried to post earlier so I apologize if my other post finally comes up and there are duplicates.

I am fairly new to SQL and am having problems trying to put together a subquery. I have two queries that have so much in common that it seems like an easy join. My problem is that each query is looking at each line of each transaction for a certain line object (111 is for purchases and 444 is for markdowns). Right now I am running the two and merging outside my current application. I'm not sure if I can use a SELECT statement (using the Markdowns statement as a field in the Purchases statement) in the columns/fields portion but I have tried and failed at that.

Ideally I'd like to be able to take the markdowns and divide them by the purchases to get the % discount and filter only those that are greater than 60% discount but right now I would be happy if I could get a solid subquery going. Below is are the two SQL statements I am running.

SELECT a.store_no as Field_a, a.transaction_date as Field_b, a.transaction_no as Field_c, a.register_no as Field_d, a.cashier_no as Field_e, SUM(b.gross_line_amount) as Field_f
FROM DevDB.transaction_header a, DevDB.transaction_line b, DevDB.store c
WHERE a.transaction_id=b.transaction_id
AND a.store_no=c.store_no
AND (a.transaction_date Between {{From date is *}} and {{To date is *}}
AND b.line_object = 111
AND b.line_action = 11)
AND EXISTS (SELECT bb.gross_line_amount
FROM DevDB.transaction_header aa, DevDB.transaction_line bb, DevDB.store cc
WHERE aa.transaction_id=bb.transaction_id
AND aa.store_no = cc.store_no
AND aa.transaction_id = a.transaction_id
AND (aa.transaction_date Between {{From date is *}} and {{To date is *}}
AND bb.line_object = 444
AND bb.line_action = 44))
GROUP BY a.store_no,a.transaction_date,a.transaction_no,a.r egister_no,a.cashier_no

SELECT a.store_no as Field_a, a.transaction_date as Field_b, a.transaction_no as Field_c, a.register_no as Field_d, a.cashier_no as Field_e, SUM(b.gross_line_amount) as Field_f
FROM DevDB.transaction_header a, DevDB.transaction_line b, DevDB.store c
WHERE a.transaction_id=b.transaction_id
AND a.store_no=c.store_no
AND (a.transaction_date Between {{From date is *}} and {{To date is *}}
AND b.line_object = 444
AND b.line_action = 44)
GROUP BY a.store_no,a.transaction_date,a.transaction_no,a.r egister_no,a.cashier_no

Thank you to any help you can give me.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Subquery in Columns/Fields


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway