how to write a oracle sql query order by two columns - oracle

I have a table include two columns, year and month, I want get a unique result that order by year and month.
example:
y m
2013 12
2012 1
2013 4
2012 3
I want get
y m
2013 12
How to write the SQL query. thanks.

select * from table where y = 2013 and m = 12;
Do you want this ?

Related

PowerBI - Pivot Rows on Matrix Visualization - Month + 1

I have a dataset in the following format. Notice InitialDate of July
2022 has 1 corresponding row of RollingDate and Churn, June 2022 has
2 corresponding rows, May has 3 etc etc
Which I'm looking to display the results in a table matrix like this.
The issue I'm finding it is that if I just use RollingDate as the
Columns and Churn as the Values, it looks like this
But what I want is this
Add a Rank column to the table as follows:
Rank =
VAR __InitialDate = 'Table'[InitialDate]
RETURN
RANKX(
FILTER( Table , Table[InitialDate] = __InitialDate ),
Table[RollingDate],
,ASC
)-1

Calculate last year group by ID with DAX

I have a table in SSAS Tabular Model like this
Table 1
ID END DATE
1 06/24/2016
1 06/24/2017
1 06/24/2018
2 08/08/2017
2 08/08/2016
3 12/12/2015
I would like to create a Mesure in DAX, in another related Table. The output should be this:
Table 2
ID MAXYEAR
1 2018
1 2018
1 2018
2 2017
2 2017
3 2015
PLEASE !!! WITHOUT USING EARLIER. Because my model is very large, and canĀ“t use this function.
Create a relationship between the 2 tables, assuming that Table 2
contains unique values for ID.
Create a year column from end date
Year = year([END DATE])
After that, in Table 2 create a calculated column with the following code:
MaxYear = CALCULATE(max('Table'[Year]))
Table 2 should look like this

How to complete report derived from another query with zeros or nulls

So, I'm really having a hard time with a report.
I need a report grouped by year. For example, we want to show how many cars are sold per year. So, the report has a column Year, the type/model of the car, and the quantity. However, I also want to show a row with null/zero value, so even when no car of a specific type was sold, I want it to show the row, but with 0.
The problem is, this query is based on a lot of views, which shows each transaction. So, my actual query works fine except it doesn't show a type when none of that type was sold in a year.
When I pivot this report using Oracle APEX, it almost works. It shows all the types, but if I filter per year, then they are gone.
I have all the years I need, but I don't have the data for that year. I take all the data from multiple views with the specifics of the sales. Some of the models/types were not sold in some years, so when I query the report, it doesn't show up, which is expected. For example:
What I get is
//YEAR - MODEL - QUANTITY //
2018 - MODEL 1 - 300
2018 - MODEL 2 - 12
2017 - MODEL 1 - 12
2017 - MODEL 2 - 33
2017 - MODEL 3 - 22
What I want
//YEAR - MODEL - QUANTITY //
2018 - MODEL 1 - 300
2018 - MODEL 2 - 12
2018 - MODEL 3 - 0
2017 - MODEL 1 - 12
2017 - MODEL 2 - 33
2017 - MODEL 3 - 22
Any ideas?
You can conjure rows, and outer join to them.
with years as (
select add_months(date '1980-1-1', (rownum-1)*12) dt
from dual
connect by level < 5
)
select y.dt, count(e.hiredate)
from scott.emp e
right outer join years y
on y.dt = trunc(e.hiredate,'yy')
group by y.dt
DT COUNT(E.HIREDATE)
------------------- -----------------
01-01-1982 00:00:00 1
01-01-1983 00:00:00 0
01-01-1981 00:00:00 10
01-01-1980 00:00:00 1

Powerpivot Rankx with multiple filters

I want to assign a row number for [Site] after it's filtered based on three simple criteria: whether they have the same [Year], [Identifier], and where the [LeftOrJoined] column is "JOINED".
So I want the [Rank] column below:
[Year] | [Identifier] | [LeftOrJoined] | [Site] | [Rank]
2012 1 LEFT A
2012 1 JOINED B 1
2012 1 JOINED C 2
2013 2 LEFT A
2013 2 JOINED B 1
2013 2 JOINED C 2
The formula I have is:
Rankx(
filter(table,
allexcept(table,
[LeftOrJoined]="JOINED",[Year]=[Year],
[Identifier]=[Identifier])),
[Site], ,1,dense)
But I get the error: The ALLEXCEPT function expects a table reference expression for argument '2', but a string or numeric expression was used.
I feel I'm making a basic mistake. Any help greatly appreciated!
I'm not sure exactly how your formula is supposed to work, but the following works for me:
Rank = IF(Table[LeftOrJoined] <> "JOINED", BLANK(),
RANKX(FILTER(Table, Table[LeftOrJoined] = "JOINED"),
Table[Site], , 1, Dense))
If LeftOrJoined is not "JOINED", then return a blank, otherwise, rank the Site on the rows where LeftOrJoined is equal to "JOINED".

How to query on a specific date and time range using hive query language taking input from the user?

I have a table in a database in hive.
The table is partitioned based on year month and day.
My query looks something like this
select entity1,entity2
from table_t
INNER JOIN tab_roll.cha alias2
ON alias1.sid = alias2.sid
INNER JOIN net_roll.net alias3
ON alias2.id=alias3.id
where event= 'unknown'
and day >= 10 and day < 12
and month >= 5 and month < 11
and year = 2014
now I want to get results between say mm-dd-yyy HH : MM :SS and mm-dd-yyy HH : MM :SS, how should I do that?
Is is possible to have a pop up where the user chooses the date/time ranges?
Don't know if this helps but the data has about 500 million rows.
Thanks
I think Between should work for you. & to optimize this you can index that column too.

Resources