Using a 0 rather than skipping the group entirely if nothing is found - google-sheets-formula

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

Related

oracle Unable to create AWR report

oracle version: 11.2.0.1.0
When I try to generate an AWR Report in Oracle use sysdba,
exec dbms_workload_repository.create_snapshot();
I keep getting this error:
ORA-00600: [kewrose_1], [600], [ORA-00600: [13013], [5001], [6213], [8465936], [5], [8447794], [17], [], [], [], [], []
], [], [], [], [], [], [], [], [], []
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this
conn / as sysdba
SQL> #$ORACLE_HOME/rdbms/admin/awrrpt.sql
SQL> #$ORACLE_HOME/rdbms/admin/awrrpt.sql
Current Instance
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
3400239050 TEP 1 TEP
Specify the Report Type
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt. Default value is 'html'.
'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report
Enter value for report_type: dec
Type Specified: dec
Instances in this Workload Repository schema
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 3400239050 1 TEPCBC TEP oldman
Using 3400239050 for database Id
Using 1 for instance number
Specify the number of days of snapshots to choose from
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing without
specifying a number lists all completed snapshots.
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing without
specifying a number lists all completed snapshots.
Enter value for num_days: 1
Listing the last day's Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
TEP TEP 38542 20 Dec 2022 00:30 1
38543 20 Dec 2022 01:30 1
38544 20 Dec 2022 02:30 1
38545 20 Dec 2022 03:30 1
38546 20 Dec 2022 04:30 1
38547 20 Dec 2022 05:30 1
38548 20 Dec 2022 06:30 1
38549 20 Dec 2022 07:30 1
38550 20 Dec 2022 08:30 1
38551 20 Dec 2022 09:30 1
38552 20 Dec 2022 10:30 1
38553 20 Dec 2022 11:30 1
38554 20 Dec 2022 12:30 1
38555 20 Dec 2022 13:30 1
38556 20 Dec 2022 14:30 1
38557 20 Dec 2022 15:30 1
38558 20 Dec 2022 16:30 1
38559 20 Dec 2022 17:30 1
38560 20 Dec 2022 18:30 1
38561 20 Dec 2022 19:30 1
38562 20 Dec 2022 20:30 1
Specify the Begin and End Snapshot Ids
Enter value for begin_snap: 38542
Begin Snapshot Id specified: 38542
Enter value for end_snap: 38544
End Snapshot Id specified: 38544
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_38542_38544.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: test2
Using the report name test2
<html lang="en"><head><title>AWR Report for DB: TEP, Inst: TEP, Snaps: 38542-38544</title>
<style type="text/css">
body.awr {font:bold 10pt Arial,Helvetica,Geneva,sans-serif;color:black; background:White;}

Storing a date as a variable and using it in code (Oracle)

Oracle Version: 19.2.1.247
Good morning,
I am trying to get the most recent Friday and then store that date to use as a variable. I need to only bring forward those people who have a start date of 28 days or earlier from "my_date". Anyone over 28 days should be excluded.
here is what I have so far:
variable my_date varchar2(30)
exec :my_date := sysdate;
SELECT Distinct * from tbl1.people
where startdt < to_date(:my_date,(select next_day(trunc(sysdate-1), 'FRIDAY'-7 from dual))-35;
I am getting the following error message and I am not sure how to handle it:
ORA-00932: inconsistent datatypes: expected date got date
Here is an example of what I am trying to do:
Last Friday (Oct 23, 2020) is "my_date", so I need to go backwards for 28 days to Sept 25, 2020 and use that as the cutoff date. I do not want to see anyone with Sept 24,2020 or earlier.
The result set should be from Sept 25, 2020 to Oct 23, 2020 only.
Thank you for any help you can give!
To me, it looks as simple as
select *
from your_table
where startdt < next_day(sysdate - 7, 'FRIDAY') - 28;
because
SQL> select next_day(sysdate - 7, 'FRIDAY') - 28 from dual;
NEXT_DAY(S
----------
25.09.2020
SQL>

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

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

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;

Resources