oracle query to convert number format to date format or vice versa - oracle

In DB, date is stored in number format (Mon Jul 07 14:41:40 IST 2014
is stored as 1404724300383), I need a query to convert number to date to compare with the sysdate, or from sysdate to number format. How can we convert the date to number or vice versa?

Assume the number is a sequencial one based on specific rule. You need to know the rule first.
Get the rule
a) 07 July 2014 = 1404724300383; 07 July 2013 = ? (assume 1404700000000)
b) Assume value 0 mapping to one day, Day1
c) two formulas 1404724300383 = (07 July 2014 - Day1) * RULE; 1404700000000 = (07 July 2013 - Day1)*Rule;
Then, Rule = 24300383/365 and Day 1 = 1 Jan 1900 + 41285/(1404724300383/1404700000000*41460/((1404724300383/1404700000000)-1))
where 41825 is the days between 07 July 2014 and 1 Jan 1900)
41460 is the days between 07 July 2013 and 1 Jan 1900)
Use the Rule and Day1 to get what you need
select Day1 + [query column]/Rule from Your_Table;

Related

Using a 0 rather than skipping the group entirely if nothing is found

How can I use a 0 as a "placeholder" here?
=QUERY(Data!A1:G578, "select G, sum(C) where D='Income' group by G label sum(C) 'Total Income'")
So that
Month
Total Income
August 2021
$784.59
October 2021
$200.00
November 2021
$312.74
becomes
Month
Total Income
August 2021
$784.59
September 2021
$0.00
October 2021
$200.00
November 2021
$312.74
The quickest hacky fix would be just to have an entry of 0$ for September in the data somewhere, but I am wondering if there is a more ""professional"" way to do it

Grabbing all rows from a database that have specific column values in laravel

I am dealing with a table that has a bunch of short names, ex.
some_id
long_name
short_name
94
March
mar
19
April
apr
0
June
jun
2
September
Sep
I want to grab only a few supported short names, ex. mar, sep, jun.
How would I go about doing it in laravel?
Currently I have something like this:
$this->result = DB::table('table_above')->get();
But this just grabs every table. I was thinking of adding the where command, but not sure how to check for multiple values.
$this->result = DB::table('table_above')->where('short_name', [somehow say either mar, sep, jun])->get();
At the end I'd like an array that holds a dictionary of rows (i.e $result) with the supported short names (i.e here mar, june, sept).
Try this query
DB :: table ('table_above')->whereIn('short_name', ['mar', 'sep'])->get()

Working with a date column that corresponds to values in another column in SAS

I would like to add on to this code so that the value of the last measurement according to the "date" column in the "measurement" column is divided by the lowest value recorded in the measurement column and the result forms a new column. The current working code adds a column that subtracts the initial measurements from the other measurements in the "measurement" column if the "subject", "type" and "procedure" columns match. Thank you in advance.
data have;
input Subject Type Date $ 5-12 Procedure $ 15-22 Measurement;
datalines;
500 Initial 15 AUG 2017 Invasive 20
500 Initial 18 SEPT 2018 Surface 35
500 Followup 12 SEPT 2018 Invasive 54
428 Followup 2 JUL 2019 Outer 29
765 Seventh 3 JUL 2018 Other 13
500 Followup 6 NOV 2018 Surface 98
428 Initial 23 FEB 2018 Outer 10
765 Initial 20 AUG 2019 Other 19
610 Third 21 AUG 2018 Invasive 66
610 Initial 27 Mar 2018 Invasive 17
;
data want (drop=rc _Measurement);
if _N_ = 1 then do;
declare hash h (dataset : "have (rename=(Measurement=_Measurement) where=(Type='Initial'))");
h.definekey ('Subject');
h.definedata ('_Measurement');
h.definedone();
end;
set have;
_Measurement=.;
if Type ne 'Initial' then rc = h.find();
NewMeasurement = ifn(Measurement=., ., sum (Measurement, -_Measurement));
run;

Pivot Dynamic Data in Oracle

I have rollup output of month-wise average sales of products in a quarter as shown below:
Rollup output:
Product Month Sales
------------------------------
Product1 MAY 101.27
Product2 MAY 5.47
Product1 JUN 1481.19
Product2 JUN 84.95
ALL QTR 836.44
I need final output in the following format:
Product1 Product2 AverageSales
May 101.27 1481.19 (null)
Jun 5.47 84.95 (null)
Jul 0 0 (null)
ALL (null) (null) 836.44
I tried to apply pivot on month but since month name is a dynamic value based on the quarter selected, I tried to pivot on the product:
select * from (rollup output)
PIVOT MIN(Sales) FOR Product IN ('Product1' AS Product1_sales, 'Product2' AS Product2_sales, 'ALL' AS Average Sales');
I received the following output:
MONTH Product1_sales Product2_sales Average Sales
MAY 5.47 (null) (null)
MAY (null) 101.27 (null)
JUN 84.95 (null) (null)
JUN (null) 1481.19 (null)
Qtr (null) (null) 836.44
However, I need data in the final format mentioned above. How can I achieve this?
Also, if data for a given month of the quarter is not available, I want to display its value as 0 (also shown in the final format above). How can I achieve that, considering that month name is dynamic?
Edit: I can pivot using product as well since I do not want xml output that comes out of dynamic pivot.
I'm not sure why it needs to be dynamic since the number of months is unlikely to change. Why not just:
select product
, nvl(jan,0) as jan
, nvl(feb,0) as feb
, nvl(mar,0) as mar
, nvl(apr,0) as apr
, nvl(may,0) as may
, nvl(jun,0) as jun
, nvl(jul,0) as jul
, nvl(aug,0) as aug
, nvl(sep,0) as sep
, nvl(oct,0) as oct
, nvl(nov,0) as nov
, nvl(dec,0) as dec
from rollup_output
pivot (min(sales) for (month) in
( 'JAN' as jan, 'FEB' as feb, 'MAR' as mar, 'APR' as apr, 'MAY' as may, 'JUN' as jun
, 'JUL' as jul, 'AUG' as aug, 'SEP' as sep, 'OCT' as oct, 'NOV' as nov, 'DEC' as dec)
);
SQL Fiddle

How to get only the date in MVC

In MVC, right now in my view data format is: 25/06/1992 12:00:00 AM But i want only date: 25 jun 1992 in this format
string bdate = WMU.DOB.ToShortDateString();
string entrydate = WMU.EntryDate.ToShortDateString();
You can use dateTime.ToString("dd MMM yyyy"); for 25 Jun 1992

Resources