What's an elegant way to find the minimum value in each row of a table? - sql

I've got a table which has a row per product, and the price that product has on ten different merchants. What I'd like to see is the minimum price each product has among those different merchants.
In Excel this would be easy, because the MIN() function there works on any set of cells, whether they're arranged horizontally or vertically. However, MIN() in SQL only acts on columns, so I'd be able to find the cheapest price merchant 1 had across all products, etc.
Is there an elegant way to obtain the minimum price for each row? (Are there OLAP functions that would do this, or does the problem have to be approached using a loop?)

In PostgreSQL, you can do:
select least(price1, price2, price3, ..)
from products
LEAST gives you the minimum value of a list of values. It's the non-aggregate version of MIN.

Related

Selecting top 10% of the customers using SQL query

I have a table known as Customers.
I want to fetch 10% of the customers based on the order they appear in the table.
I am not sure about how to do this in SLQ?
I know I can use "top" and specify the number. But since the customer count changes everyday I want to pick this up based on the %.
Example what I tried,
select top 100 email-address, cid
from Customers

Group by in Orange, Data mining

I have a dataset for a supermarket, each transaction containing an item is represented in a row. So, if transaction 1 contained milk, bread and coffee, the items are on a separate row and the attribute transaction occurs three times. What I want to do is to group transactions by item so that all the items are concatenated in one column. Then lastly apply association rules and separate each item in a column as an itemset. Is this even possible in Orange?
Worth mentioning, I managed to do this in RapidMiner easily with the same dataset. I used the Aggregate operator, concatenated the item attributes and then grouped by transactions.
If I understand this correctly, you wish to aggregate columns, not rows. If so, there's Aggregate Columns widget available for that. To perform Group by on rows, there's currently Pivot, which has a Group by output. We are working on a separate Group by widget, which should be available in the next release.

DAX Need Power Pivot Measure to be SUM of ALL Columns in Each Column. How to ignore column context

I have a Pivot Table with Salespeople as columns. I have income measures that correctly show (in the rows) the income each of them produced. However, I would like to show everyone's income in each column on some of the measures.
The reason is I want them to be paid on some income items (row measures) on the total of all salespeople not on their individual production.
Is there a way to make a measure ignore the column context?
DAX ALL
Try to use ALL function and give your column as a parameter.
It will clear currently applied filters.

Form/Query: A row of a table, plus two editable fields from two different rows of a 1:n related table

I have three tables, one holding material-data (materials), one holding suppliers (suppliers) and one holding prices per supplier and material (supplierPrices). One material can have multiple prices, one price per supplier.
I have a form that displays various material-data per row. This form also displays an editable price of a specific supplier (supplierID 100). The table relationship in the query is "include all rows of materials where the joined fields are equal" and in the criteria supplierID = 100. So there's exactly one row per material, including the editable price of that supplier.
But now i would like to display a second editable price per row, the price of supplierID 200. If i extend the criteria to "supplierID = 100 OR supplierID = 200" i get two rows per material, which is not what i want. What i want is to display both prices in one row, together with the big bunch of material-data. First i did it with a VBA function, calling it in the query, but then the controlsource is an expression and data can't be edited respectively stored.
Is there a way to do this with some special select in the query? Or would i rather have to use VBA (again) to store it in the proper table?
Thanks for your hints.
TRANSFORM Max(supplierPrices.[price]) AS price
SELECT supplierPrices.[materialID]
FROM supplierPrices
GROUP BY supplierPrices.[materialID]
PIVOT supplierPrices.[supplierID];
but this is readonly.

combining multiple SSAS queries as one dataset

I have a fact-table with one date dimension linked three times to attributes for Ordered, Prepared and Shipped dates. So, I am able to get counts on ordering, manufacturing and dispatch and currently I am running these as three separate excel pivot table requests and combining them into one graphs giving three bars per month. I am wondering if there is a more sleek way I should be doing this by which I write a query which returns the three separate counts as individual measures rather than running the query three times doing it once against each dimension.
Currently, the fact table looks something like this: -
DEPID, PRODCODE, ORDERDATE, PROCESSDATE,SHIPDATE
001,001,20120101,20120102,20120104
002,001,20120103,20120105,20120106
003,002,20120104,20120106,20120107
004,002,20120105,20120107,20120108
You could create 3 calculated measures in the cube (Ordering Count, Manufacturing Count, Dispatch Count)...then just drag them into your pivot table in the values section and use a date dimension in the rows group.