sql query and sum the two fields - sql

I want to display unit price, quantity but my problem is I want to multiply the unit price * quantity. How to combine this 3 fields? I want the result like this:
UNITPRICE QUANTITY AMOUNT
2 3 6
2X3 equals 6.. please help me how to query this..
thank you newbie in multiplying table

I made this sqlfiddle for you. Perhaps it will help you.
select
UNITPRICE,
QUANTITY,
UNITPRICE * QUANTITY as [Amount]
from data

Related

SQL - how to show SKUs with the lowest price from a query

I am making a query for a price comparison site and I have to provide them a csv file with certain data. I have done the query and the first problem was that the prices that showed up in it were the full prices from sql database. So when we have for example a discount applied to the whole category of products the price shown is still the full price not the discounted one. I solved that by checking if an SKU is in a discounted category and the query calculates the price accordingly.
The new problem is now that a query checks through categories and if one sku is in multiple categories it creates a row with same SKU for each category and I end up with multiple rows with same SKU and only one has correct price (discounted one).
Example query result. NOTE that the Price column is a calculated result not the data from the table.
SKU
Product
Price
A
Ball
19
A
Ball
19
A
Ball
15
B
Cube
10
B
Cube
8
How do I filter it to just this
SKU
Product
Price
A
Ball
15
B
Cube
8
You need GROUP BY with aggregate function MIN()
SELECT SKU
, Product
, MIN(Price) as Price
FROM <table>
GROUP
BY SKU
, Product

How to count and categorize values by the same criteria

I have a table in SQL Server with just 2 columns, the ProductID and the Discount.
There are many products registered in rows.
So, I want to know how many products there are in this table with the same discount, categorized by the discount column value.
How can I query this by the easiest and simplest way?
The view that I expect for:
Discount - QTD
-------------------
0.25 - 150
0.40 - 320
0.75 - 532
It seems like a simple aggregation should do the trick.
Select Discount
,QTD = count(*)
From YourTable
Group By Discount

PostgreSQL question - finding sum of sales by state

I need help writing the query, we have a table called SALES, which has 3 columns as below:
Column Names: sale_id, state, sale_amount_cents
I assume the sale_amount_cents has the sale amount in cents as opposed to dollars, and our end answer needs to be in dollars so we would have to multiply by 100.
Can someone please help writing the query to sum sales, in dollars, by date, rounding to two decimal places, and sorting from the greatest sale amount to the least?
I assume the query would look like this:
UPDATE SALES SET sale_amount_cents=sale_amount_cents*100
SELECT SUM(sale_amount_cents) from SALES
GROUP BY STATE
ORDER BY sale_amount_cents DESC;
select state, SUM(sale_amount_cents)/100 as Sales_in_dollar from SALES
GROUP BY STATE ORDER BY SUM(sale_amount_cents) DESC

Issue with finding out a percentage from the average in Postgres

Before I introduce my issue, I must specify that I am a beginner with SQL and Postgres.
I've made a database in Postgres, as a part of a project and I need to interrogate it. The database is about a firm which sells fertilizer.
One of the request is that I need to write a query that will return the Stores with Sales of 25% of the average of the total sales.
I have found out the average of the Sales by using the following query:
SELECT StoreID
FROM Sales
WHERE Price < (SELECT ROUND(AVG(Price)) FROM Sales);
Now, I don't know what should I put in the query to get the result.
Can anyone guide me?
If you mean sales with price below 25% of the average:
select storeid
from (
select storeid, price, avg(price) over() as avg_price
from sales
) s
where price < 0.25 * avg_price

Query Help to determine average price for products < 3

Hi I've been working on this query, and I can't quite figure out the where statement to show only the average price of products < 3
"List each Product Class, number of items in the class and the average Price (name this Avg_Price, Format $0.00) of the items in the class. List only those classes that have less than three (3) items"
This query shows me the results of the average prices of the products (results in image)
COLUMN Avg_Price FORMAT $999,999.00
SELECT Product_Class, COUNT(*), AVG(Price) AS Avg_Price
FROM Product
GROUP BY Product_Class;
I need help only showing the counts avg PRICE that is < 3
Include Having at the end
HAVING count(*) > 3