**** SOLVED ****
SELECT price
FROM inventory
WHERE price > ANY (SELECT price FROM inventory WHERE type = 'new');
Thank you to Mohammed Shafeek and every one else that commented.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I am trying to check if a price is higher than any of the prices in a sub-query.
SELECT price
FROM inventory
WHERE price > price IN (SELECT price FROM inventory WHERE type = 'new');
So I want to be able to check if a price is higher than at least one of the values from the sub-query.
Any help would be much appreciated.
**** EDIT ****
Example of what i mean
$20 > $15, $30, $50
So because $20 is greater than $15 it would be selected
Would this be Min(price)
Like mentioned in below comments
Thanks in advance.
One method uses aggregation:
SELECT price
FROM inventory
WHERE price > (SELECT MAX(price) FROM inventory WHERE type = 'new');
Another uses the ALL operator:
SELECT price
FROM inventory
WHERE price > ALL (SELECT price FROM inventory WHERE type = 'new');
SELECT price
FROM inventory
WHERE price > ANY (SELECT price FROM inventory WHERE type = 'new');
I think this is the query actually u want.Check it
Related
In SQL, Please is this correct?
SELECT COUNT (Price)
FROM orders
WHERE Price > AVG(Price);
you can try sth like this
SELECT customers FROM orders WHERE price > (select AVG(price) from orders) ;
I need to write SQL query for "average number of particular product sold by date. On each day is sold min one product".
SELECT AVG (COUNT (PID))
FROM SOLD
GROUP BY DATE, PID;
P.S. PID means Product ID.
Is this query okay?
Should this give right answer?
Consider Using distinct count of date columns
SELECT PID,
COUNT(PID)/COUNT(distinct date_) as "Avg.Product Sold By Days"
FROM SOLD
GROUP BY PID;
You can try this sql query below. Basically, it will return the average number of 'SALES' for each product you have. It will group by each distinct product ID. Please provide us the data structure your of table and etc.
SELECT product_ID, trans_date
Sum(sales_of_product) / COUNT(DISTINCT sold_transaction) AS 'avg'
FROM SOLD
GROUP BY product_ID
Please excuse my formatting... I am working on that.
I am trying to select the correct price of a project in my query based off the appropriate effective date.
For example we have a table that has the following information
Price Table-------------------------
Item Price effectiveDate
A $0.57 1/1/17
A $0.72 6/1/17
Now I have a production table that contains what was produced that day and it will list out their quantity and the production for a production date.
Production Table-------------------
Item Quantity productionDate
A 100 2/1/17
A 100 7/1/17
Now when I query these I want to be able to select the appropriate price given the productionDate and effectiveDate.
What is the best way to achieve this?
Try the following (first select the highest effectiveDate lower than the productionDate, then get the price for that date):
SELECT preselection.Item, Price FROM
(SELECT Production.Item, Max(effectiveDate) As MaxEffectiveDate
FROM Production INNER JOIN Price ON Price.item = Production.Item
Where Price.effectiveDate <= productionDate GROUP BY Production.Item) As preselection
INNER JOIN Price ON Price.Item = preselection.Item
AND Price.effectiveDate = preselection.MaxEffectiveDate
I need to select products (their names) and prices records that have an above average price, but cheaper than 33
My request:
select ProductName, Price
from Products
where Price>(select avg(Price) from Products)
and
Where Price < 33;
It's not working. Why?
Thank you in advance.
Remove the duplicate where like so:
select ProductName, Price
from Products
where Price > (select avg(Price) from Products)
and Price < 33;
My Access table has product name and price for each record. I want to get a count of all records with price less than a current record's price. How do I use the count function to do this? Thanks.
Access type:
SELECT Table1.ID, DCount("*","Table1","Price<" & [Price]) AS NumCheaper
FROM Table1
This will show #Error where there is a null price.
More general:
SELECT a.ID, a.ANumber,
(SELECT Count(*) FROM Table1 b
WHERE b.ANumber<a.ANumber) AS Num_Cheaper
FROM Table1 a
This will show 0 where there is a null price.
Try this
SELECT COUNT(PRODUCT_ID) WHERE PRICE < [YOUR_CURRENT_PRICE] GROUP BY PRODUCT_ID