Value Lookup

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Value Lookup

Good Evening,

 

I am trying to lookup the value in another column of the table based on the value in different column of the same table.  For an example, if I have a three column table : one column is the product ID, another -  the number of products sold, and last -  total sales in $.  I am trying to write a code to locate the quantity of the product and its ID that  was in most demand (for sales) and what was the corresponding sales for this product in $?

 

Hope this is not too confusing.

Thank you.


Accepted Solutions
Solution
‎05-22-2016 12:55 AM
Super User
Posts: 5,385

Re: Value Lookup

Not really what I would call a lookup rather an aggregate filter.
For this SQL is "perfect".
Do a group by and filter out the highest sales using the having clause.
Data never sleeps

View solution in original post


All Replies
Solution
‎05-22-2016 12:55 AM
Super User
Posts: 5,385

Re: Value Lookup

Not really what I would call a lookup rather an aggregate filter.
For this SQL is "perfect".
Do a group by and filter out the highest sales using the having clause.
Data never sleeps
Occasional Contributor
Posts: 17

Re: Value Lookup

Thank you for advice. What if I have a column ID in another data set. Would you suggest importing all the columns into a combined table first and then lookup the corresponding values in other columns?
Super User
Posts: 5,385

Re: Value Lookup

Now I'm confused.
What does your data look like?
Please attach sample data and desired output.
Data never sleeps
Occasional Contributor
Posts: 17

Re: Value Lookup

[ Edited ]

I have two tables:

One has the actual sales data:

 Date         Product_ID   Quantity Sold        $ Sales
9/20/2014             11                   78               390
9/21/2014            157                 100             200
9/22/2014             287                500           5000
9/23/2014              14                 280           4200
9/24/2014              11                   10               50
9/25/2014             287                161           1610

 

The other- a table with the numbers of products we need to do a query on:

Product_ID
11
287
40
63

 

As can be seen from the query table above, not all products IDs have been actually sold over given time period.  The output needs to give detail only on the items that actually sold, and look something like the below or other suitable format:

Product_ID Total_Quantity_Sold
11                         78
11                         10
287                      500
287                      161

 

 

Thank you for your help

.

Super User
Posts: 5,385

Re: Value Lookup

Still a bit confused... 😊
In your result, why do you have multiple rows per id? What does each row represent?
Your other table holds only the id so I don't understand why you need to query that table. Querying the sales table should be sufficient.
Data never sleeps
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 353 views
  • 0 likes
  • 2 in conversation