I have a dataset with several orders and their respective purchases (called products). The orders are linked to the products they purchased. For a given product P1, I would like to get a list of all "linked" products (i.e. products that were purchased in the same orders as P1) with the number of occurrences (i.e. the number of orders that purchased those "linked" products)
In gremlin, I have already constructed a graph connecting all orders to their respective purchases. I am using Cosmos DB in case that is important. I am able to query all orders that purchased P1:
g.V().hasLabel('PRODUCT').has('id', '2').in('purchased')
I am also able to query all linked products:
g.V().hasLabel('PRODUCT').has('id','2').in('purchased').out('purchased')
However, the first query only returns the orders that purchased P1, and the second only returns the "linked" products. I am unable to get the number of occurrences of each "linked" product. Does anyone have any advice? Thanks in advance...
That's a classic recommendation query. Basically, you're only missing the final step:
g.V().has('PRODUCT','id','2').
in('purchased').
out('purchased').
groupCount()
However, you probably don't want to include the initial product in your result:
g.V().has('PRODUCT','id','2').as('a').
in('purchased').
out('purchased').
where(neq('a')).
groupCount()
Related
I am writing a query for a SQLite database in which I need to find the best selling product for each region in a list of 6 regions. However, some of the regions don't have any product sold in which case I am supposed to output 'No Product Sold'. I am trying to use an ifnull() statement, but can't get it working.
Currently, my query is as follows
SELECT area.name AS region,
CASE ifnull(sales.area_id, 'No Product Sold')
END AS most_sales
FROM product
JOIN sales ON product.rank = sales.rank
GROUP BY area name
I also know I will likely need to use a nested query, but I'm not sure how yet.
Unfortunately I cannot base this off of rank, it has to be the item with the highest sales in the region. Does anyone know what I am doing wrong?
I am querying my graph where it has the following nodes:
Customer
Account
Fund
Stock
With the following relationships:
HAS (a customer HAS an account)
PURCHASED (an account PURCHASES a fund or stock)
HOLDS (a fund HOLDS a stock)
The query I am trying to achieve is returning all Customers that have accounts that hold Microsoft through a fund. The following is my query:
MATCH (c:Customer)-[h:HAS]->(a:Account)-[p:PURCHASED]-(f:Fund)-[holds:HOLDS]->(s:Stock {ticker: 'MSFT'})
WHERE exists((f)-[:HOLDS]->(s:Stock))
AND exists ((f:Fund)-[holds]->(s:Stock))
AND NOT exists((a:Account {account_type: 'Individual'})-[p:PURCHASED]->(s:Stock))
RETURN *
This almost gets me the desired results but I keep getting 2 relationships out of the Microsoft stock that is tied to an Individual account where I do not want those included.
Any help would be greatly appreciated!
Result:
Desired Result:
There is duplications in your query. Lines 2 and 3 are the same. Line 2 is a subgraph of Line 1. Then you are using the variables a, p and s more than once in line 1 and line 4. Below query is not tested but give it a try. Please tell me if it works for you or not.
MATCH (c:Customer)-[h:HAS]->(a:Account)-[p:PURCHASED]-(f:Fund)-[holds:HOLDS]->(s:Stock {ticker: 'MSFT'})
WHERE NOT exists((:Account{account_type: 'Individual'})-[:PURCHASED]->(:Stock))
RETURN *
It seems to me that you should just uncheck the "Connect result nodes" option in the Neo4j Browser:
I'm looking for small help. I'm using this function in function.php. When I use a shortcode [total-product] I'll get for example "We have a total of 1000 products in stock".
Using Get the count of all "In stock" products in WooCommerce code, takes a number of products from all categories, but I need to get number just only from specific categories - not from all together.
I don't know how to change the SQL query to select from specific categories, eg by ID.
Is there any chance of counting the number of product "in stock" according to specific categories? Something like (I have no idea about Database structure of WP tables):
AND category_id LIKE '100;101;...' // one or more category IDs
Table structure
The above Table have 10 products with various price from 3 suppliers. I need to pick the supplier who can give the lowest price.
Just i tried with MS Access 2013. I unable to get the lowest price. Your valuable guidance is much appreciate one.
SID = Supplier ID
PCODE = Product Code
Thank you very much for your time
I assume cheapest means lowest per-ml price per item
So do the following:
create a query#1 that includes the product, supplier, whatever other
fields you want in the final answer, and a calculated field of the
per-ml price.
create an aggregate query #2 on query#1, which groups by product and gives the min per_ml_price. Now you have a "table" with the cheapest price for each product.
Lastly, you want to find the data that matches the lowest price. (Inner-)Join query#2 and query#1, and output the fields you want (product, supplier, etc.)
I've generated a simple access report that is used for purchasing.
Basically, there are two tables, one for purchase orders, and one for the items on the purchase orders.
For the items on an order, I store the item details, quantity ordered, quantity delivered, and price per unit. (plus a few other fields which aren't relevant in the context of this question).
I'm generating a report to list all outstanding items still on order, and the report has a calculated field showing the outstanding quantity * cost per item. This works perfectly fine.
What I'm struggling with, is showing a sum of this calculated field (i.e. a total cost of all outstanding items), but when I try to add a total to the column, it only gives me the option of adding an item count for the column. The column is a 'Currency' field.
What might I be doing wrong, or am I expecting too much from access?
Resolved. I created the only option that the GUI would allow (item count), then modified the query from:
=Count(*)
to
=Sum([Quantity]*[Cost])
Works perfectly.