I have a SQL stored proc that uses a linked server and Openquery to execute a MDX query. The result returned from the MDX query is in the format of:
Month 1 | Month 2 | Month 3 | Month 4
12 5 4 7
where the columns are dynamic i.e. I never know how many months will be in the output.
How can I transpose the output into a relational format e.g.
Two columns.
Col 1 | Col 2
----- -----
Month1 12
Month2 5
Month3 4
etc etc
You'll need to change your original MDX query from something like :
Select
[Months].members on 0
from [MyCube]
to something like this one :
Select
[Measures].defaultmember on 0,
[Months].members on 1
from [MyCube]
Related
I have a MySQL table which contains val_type column which have 3 type of values
id val_type company
1 rib 1
2 mod 2
3 rib 2
4 rib 3
5 mod 1
6 trop 1
$res= SELECT SUM(val_type) from tabl_name GROUP BY company;
with above query I get sum of all types in one
Result Required : Rib=3, mod=2 and trop=1
I want to get sum of all three types with one MySQL query. like how many rib,mod and trop.
Thanks
It sounds like you want to count all three types. You only need a basic GROUP BY query:
SELECT
val_type,
COUNT(*) AS cnt
FROM tabl_name
GROUP BY
val_type;
There are 2 tables. Table with reports and phrases (search phrases). The report table has a date field and other results (not important). When writing a sql query, connect a table with phrases and take the name and frequency from it, then the fields should be built according to the dates that are in the reports (distinct). How to do this ?
All I was able to do is the usual JOIN, but what to do with the dates I don't know:
SELECT
reports.url,
reports.position,
phrases.name,
phrases.counter
FROM reports JOIN phrases ON reports.phrase_id = phrases.id
AND reports.site_id = 98
The idea of the sample should be more distinct, but as it is there insert ?
SELECT DISTINCT report_date FROM reports WHERE site_id=98
The idea is to get something:
phrase | counter | 07.06.2019 | 09.06.2019 | 10.06.2019
buy.. 100 90 1 89
sell... 50 12 3 19
The numbers below the dates are reports.position.
(yandex translate on russian)
I want to create a query to get the total number of produced products for each day in Microsoft Access.
Here are the few rows of my table as a sample:the table's name is Orders
ordernumber number of products Date
100 2 11-May-16
101 1 11-May-16
121 2 24-May-16
122 3 24-May-16
131 1 25-May-16
105 3 11-May-16
127 1 24-May-16
135 2 25-May-16
The desired output is :
TotalNoProducts Date
6 11-May-16
6 24-May-16
3 25-May-16
This is one of the more basic aggregate queries:
SELECT SUM([number of products]) As TotalNoProducts, CDate(Int([Date])) As TheDate
FROM Orders
GROUP BY CDate(Int([Date]))
Note that you can also build this query through the query builder, which is usually easier for beginners than using SQL
I have two datasets.
One dataset1 has the fields MonthNumber, MonthData.
The other dataset2 has the fields MonthNumber, MonthBase.
I want to use both the MonthData field and MonthBase fields in one dataset to create a chart.
Please help me if anyone has an idea how I can combine both datasets to one or use one field of one dataset into another?
To combine the fields from two datasets without combining the datasets you need to use the LOOKUP function.
To replicate this I created the datasets...
DataSet1
--------
MonthNumber MonthData
------------ ----------
1 12
2 23
3 11
4 8
DataSet 2
---------
MonthNumber MonthData
------------ ----------
1 10
2 15
3 20
4 25
Create a chart as you would normally for DataSet1.
Set the values to MonthData, and the Category Groups to MonthNumber
Then add a new Series in the Values area, and set the expression to
=Lookup(Fields!MonthNumber.Value, Fields!MonthNumber.Value,
Fields!MonthBase.Value, "DataSet2")
This effectively states join The ID fields DataSet1.MonthNumber, to DataSet2.MonthNumber, returning me DataSet2.MonthBase
The design will look like this
And the output like this
See also the reference here from which I derived this answer
I have a column in table A. the column name is Sequence number. The Structure of table A is numbers from 1,2,3,4.....3600.
Now on the basis of table A. I want the below output from the SQL select query for SQL server 2008.
seq no dynamic col
1 1
2 1
3 1
4 1
5 1
6 2
7 2
8 2
9 2
10 2
11 2
12 3
13 3
My Second column is getting generated at the run time.
And the business logic is that, if the seq number mod 6 = 0 then increment the value of dynamic column.
Thanks in advance
Try this:
select seqno, (seqno/6) +1 dynamiccol
from t
Fiddle Demo
Take this as pseudo code because I'm not familiar with SQL Server specifically, but it should give you somewhere to go.
SELECT
seq_no,
ROUNDDOWN(seq_no/6)+1 AS dynamic_col
FROM
my_table