When single order is having tax,discount,sales then in report all the three are displaying seperate colum w.r.to that plan. Sample planname: SALESPLAN - plsqldeveloper

Please help me to get three records in a single column. Please find the query below and help me. Thanks in advance
SELECT
salereg.currency_symbol AS currency_symbol_1,
salereg.company_name AS company_name_2,
salereg.customer_type_descr AS customer_type_descr_3,
salereg.product_name AS product_name_4,
salereg.priceline_descr AS priceline_descr_5,
salereg.charge_amount AS charge_amount_6,
salereg.discount_amount AS discount_amount_7,
salereg.adjustment_amount AS adjustment_amount_8,
salereg.tax_amount AS tax_amount_9
FROM
sales_register_summary_vw salereg,
customer_details ci,
user_entities ue
WHERE
trunc(salereg.invoice_date) BETWEEN to_date(:p_frminvoice_date, 'dd/MM/yyyy') AND to_date(:p_toinvoice_date, 'dd/MM/yyyy')
AND salereg.opentity = :p_opentity
AND salereg.customer_type = :p_customer_type
AND salereg.customer_id = ci.customer_id
AND ci.opentity_id = ue.entity_id
AND ue.is_deleted = 0
AND ue.user_id = :p_userid
GROUP BY
salereg.currency_symbol,
salereg.company_name,
salereg.customer_type_descr,
salereg.product_name,
salereg.priceline_descr,
salereg.charge_amount,
salereg.discount_amount,
salereg.adjustment_amount,
salereg.tax_amount;

Related

Summing Custom Column

First Stackoverflow question - so go easy on me :).
Hello, I am trying to flag items as "Attributed" using the following query that I have written. Essentially, if a patient ID has a PERSON_PROVIDER_RELATIONSHIP flag, they are given a 1 for that instance. If they have another type of flag (there are two other possible flags you can receive). Everything goes fine (the assigning of "1" to the instances of PERSON_PROVIDER_RELATIONSHIP), but then when I try to sum that custom column I created ("Attribution"), I get this error: (Column "Attribution" does not exist). I get this error whether I try to make another column that does the summing or when I add a "having" clause to the end where I state I only want to see records with a sum of >0. Any help would be appreciated here! I'm using MySQL to write this and am happy to provide any clarifying information.
select distinct c.empi_id as "Patient",
c.incurred_from_date as "Service Date",
(case when c.billing_organization_source_id IN ('xxxx','yyyy') then 1 else 0
end) as "In-Network Indicator",
(case when t.ref_record_type = 'PERSON_PROVIDER_RELATIONSHIP' then 1 else 0
end) as "Attribution",
(sum("Attribution") over (partition by c.empi_id)) as "Attribution Flag",
p.cleanprovidername as "Provider", t.ref_record_type
from ph_f_annotated_claim c
left outer join PH_F_Attribution_Component_Data_Point t
on t.empi_id = c.empi_id and t.population_id = c.population_id
inner join ph_d_personnel_alias a
on a.prsnl_id = t.prsnl_id
inner join xxxx_xxxx_xxxx_xxxx p
on a.prsnl_alias_id = p.NPI
where (c.bill_type_code like '33%'
or c.bill_type_code like '32%'
or c.bill_type_code like '033%'
or c.bill_type_code like '032%')
and c.source_description = 'MSSP Claims'
and c.incurred_from_date >= '2015-12-01'
and c.incurred_from_date <= '2017-01-31'
and c.population_id = '2feb2cb1-be55-4827-a21f-4e2ef1a40340'
and p.DegreeName IN ('MD','DO')
and a.prsnl_alias_type = 'NPI'
and p.PrimaryPHO = 'Yes'
group by c.empi_id, c.incurred_from_date, c.billing_organization_source_id,
p.cleanprovidername, t.ref_record_type
You can't use an aliased column name as an expression in the same SELECT clause. You have to do something like this:
sum(case when t.ref_record_type = 'PERSON_PROVIDER_RELATIONSHIP' then 1 else 0 end) over (partition by c.empi_id) as "Attribution Flag"

how to perform count using nested select in a select statement

So here is the issue. I'm trying to write a new fillrate report because the one built in is not good enough... I'm trying to run a single select statement to return both, a count of how many times an item was ordered for a specific month, and then also a count of how many times it was invoiced/shipped in full.
This code is obviously wrong, I also currently have it restricted to only look at AUG of 2015, but that is just to simplify results during testing.
I can't figure out how to do the 2nd count... This is what I was trying (brain stuck on old for each loop logic):
select inv_mast.item_id,
inv_mast.item_desc,
"YEAR" = year(oe_line.required_date),
"MONTH" = month(oe_line.required_date),
"ORDERS" = count(1),
"HITS" = (
select count(1)
from invoice_line
where invoice_line.order_no = oe_line.order_no
and invoice_line.oe_line_number = oe_line.line_no
and invoice_line.qty_shipped = oe_line.qty_ordered
)
from oe_line,
inv_mast,
inv_loc
where inv_mast.inv_mast_uid = oe_line.inv_mast_uid
and inv_mast.delete_flag = 'N'
and inv_mast.inv_mast_uid = inv_loc.inv_mast_uid
and inv_loc.location_id = '101'
and year(oe_line.required_date) = '2015'
and month(oe_line.required_date) = '8'
group by inv_mast.item_id,
inv_mast.item_desc,
year(oe_line.required_date),
month(oe_line.required_date)
order by inv_mast.item_id
To me it would seem like you could rewrite the query to use a left join on the invoice_line table instead. Without any proper test data I can't guarantee it is correct, but I think it should be.
Besides the left join I also changed to explicit joins and moved the aliases as I don't think MySQL supports the alias = column syntax.
select inv_mast.item_id,
inv_mast.item_desc,
year(o.required_date) as "YEAR",
month(o.required_date) as "MONTH",
count(1) as "ORDERS",
count(invoice_line.order_no) as "HITS"
from oe_line o
join inv_mast on inv_mast.inv_mast_uid = o.inv_mast_uid
join inv_loc on inv_mast.inv_mast_uid = inv_loc.inv_mast_uid
left join invoice_line on invoice_line.order_no = o.order_no
and invoice_line.oe_line_number = o.line_no
and invoice_line.qty_shipped = o.qty_ordered
where inv_mast.delete_flag = 'N'
and inv_loc.location_id = '101'
and year(o.required_date) = '2015'
and month(o.required_date) = '8'
group by inv_mast.item_id,
inv_mast.item_desc,
year(o.required_date),
month(o.required_date)
order by inv_mast.item_id;

Excluding a value from the return result of MySQL

I'm facing a problem and I'm not finding the answer. I'm querying a MySql table during my java process and I would like to exclude some rows from the return of my query.
Here is the query:
SELECT
o.offer_id,
o.external_cat,
o.cat,
o.shop,
o.item_id,
oa.value
FROM
offer AS o,
offerattributes AS oa
WHERE
o.offer_id = oa.offer_id
AND (cat = 1200000 OR cat = 12050200
OR cat = 13020304
OR cat = 3041400
OR cat = 3041402)
AND (oa.attribute_id = 'status_live_unattached_pregen'
OR oa.attribute_id = 'status_live_attached_pregen'
OR oa.attribute_id = 'status_dead_offer_getter'
OR oa.attribute_id = 'most_recent_status')
AND (oa.value = 'OK'
OR oa.value='status_live_unattached_pregen'
OR oa.value='status_live_attached_pregen'
OR oa.value='status_dead_offer_getter')
The trick here is that I need the value to be 'OK' in order to continue my process but I don't need mysql to return it in its response, I only need the other values to be returned, for the moment its returning two rows by query, one with the 'OK' value and another with one of the other values.
I would like the return value to be like this:
'000005261383370', '10020578', '1200000', '562', '1000000_157795705', 'status_live_attached_pregen'
for my query, but it returns:
'000005261383370', '10020578', '1200000', '562', '1000000_157795705', 'OK'
'000005261383370', '10020578', '1200000', '562', '1000000_157795705', 'status_live_attached_pregen'
Some help would really be appreciated.
Thank you !
You can solve this with an INNER JOIN on the self I think:
SELECT o.offer_id
,o.external_cat
,o.cat
,o.shop
,o.item_id
,oa.value
FROM offer AS o
INNER JOIN offerattributes AS oa
ON o.offer_id = oa.offer_id
INNER JOIN offerattributes AS oaOK
ON oaOK.offer_id = oa.offer_id
AND oaOK.value = 'OK'
WHERE o.cat IN (1200000,12050200,13020304,3041400,3041402)
AND oa.attribute_id IN ('status_live_unattached_pregen','status_live_attached_pregen','status_dead_offer_getter','most_recent_status')
AND oa.value IN ('status_live_unattached_pregen','status_live_attached_pregen','status_dead_offer_getter');
By doing a self-JOIN with the restriction of value OK, it will limit the result set to offer_ids that have an OK response, but the WHERE clause will still retrieve the values you need. Based on your description, I think this is what you were looking for.
I also converted your implicit cross JOIN to an explicit INNER JOIN, as well as changed your ORs to IN, should be more performant this way.

Data is being shown multiple times

I am having only one record under the cust_vend_relation
But its being displayed two times.
QUERY
select cvr.customer_id,
cvr.address_label,
cvr.vendor_name,
cvr.vendor_id,
vhd.locality,
vhd.area,
vhd.address,
vhd.city,
vhd.state
from cust_vend_relation cvr, vendor_home_delivery vhd
where cvr.vendor_id = vhd.vendor_id
and cvr.address_label = 'Office'
and cvr.customer_id = 3;
This is my sqlfiddle
I need to show only the records present under the table cust_vend_relation that matches with the records present under the vendor_home_delivery.
could anybody please help me .
Add Group By customer_id
select
cvr.customer_id,
cvr.address_label,
cvr.vendor_name,
cvr.vendor_id,
vhd.locality,
vhd.area,
vhd.address,
vhd.city,
vhd.state
from cust_vend_relation cvr, vendor_home_delivery vhd
where cvr.vendor_id = vhd.vendor_id and cvr.address_label = 'Office' and cvr.customer_id = 3 group by customer_id;

SSRS Chart Data Drill Through only returning 1 result

I have a Main Report with Bar and Pie Charts on it from one data source. These charts count data using an individual marker to each row, and each chart has an individual dataset with filters applied within the query.
I also have a secondary report, which I want to use to show the rows selected from within the chart. I have set this up with a multi-value parameter and no available or default results, and a filter with the 'IN' clause.
I have set up the Series properties of each chart to 'Go to Report' and pass the marker number into the multi-value parameter.
This doesn't work, and only shows me 1 row from the data region I select. How do I get it to show all the rows within the data region?
The Marker is an Integer if this helps.
If you need anymore clarification, please let me know.
Many Thanks
Update: The query for one bar chart data is as follows:
SELECT LEARNERS.Firstname, LEARNERS.Surname, LEARNERS.DOB, LEARNERS.Gender, LEARNERS.Disability, LEARNERS.NewEthnic, L_QUALS.Qual_Ref, QUALIFICATIONS_1.QualLevel, QUALIFICATIONS_1.Title, L_QUALS.DateStarted, L_QUALS.DateFinished, L_QUALS.CompletionStatus, L_QUALS.Completeness, L_QUALS.DatePlannedEnd, L_QUALS.Delivery_ID, ORGANISATIONS.Name, L_QUALS.Learner_ID, SC_Ethnic.Description AS EthnicityDesc, LEARNERS.PriorAttainLevel, SC_PriorAttain.Description AS PriorDesc, QUALIFICATIONS_1.ALIBand, LEARNERS.ContractNumber, L_QUALS.FundingStream, L_QUALS.DeliveryMethod, L_QUALS.ProgrammeType, LEARNERS.DestinationCode, SC_Dest.Description, L_QUALS.CreditsAchieved, QUALIFICATIONS.ALIBand AS FwkALIBand, L_QUALS.AimType, L_QUALS.Qual_ID
FROM L_QUALS INNER JOIN
LEARNERS ON L_QUALS.Learner_ID = LEARNERS.Learner_ID INNER JOIN
SC_Dest ON LEARNERS.DestinationCode = SC_Dest.Key_Ref AND LEARNERS.LearnerType = SC_Dest.LearnerType LEFT OUTER JOIN
QUALIFICATIONS ON L_QUALS.Sector = QUALIFICATIONS.Sector LEFT OUTER JOIN
ORGANISATIONS ON L_QUALS.Delivery_ID = ORGANISATIONS.Org_ID LEFT OUTER JOIN
QUALIFICATIONS AS QUALIFICATIONS_1 ON L_QUALS.Qual_Ref = QUALIFICATIONS_1.Qual_Ref FULL OUTER JOIN
SC_PriorAttain ON LEARNERS.PriorAttainLevel = SC_PriorAttain.Key_Ref AND LEARNERS.LearnerType = SC_PriorAttain.LearnerType FULL OUTER JOIN
SC_Ethnic ON LEARNERS.NewEthnic = SC_Ethnic.Key_Ref AND LEARNERS.LearnerType = SC_Ethnic.LearnerType
WHERE (L_QUALS.DatePlannedEnd > CONVERT(DATETIME, '2012-07-31 00:00:00', 102)) AND (L_QUALS.DatePlannedEnd <= #prmDateFrom) AND (L_QUALS.DatePlannedEnd < CONVERT(DATETIME, '2013-08-01 00:00:00', 102)) AND (L_QUALS.Qual_Ref <> 'ZESF0001') AND (L_QUALS.AimType = '1' OR L_QUALS.AimType = '4')
ORDER BY L_QUALS.Learner_ID
And the bar chart is: Data - (Count(QualID) and Category = TimelyAchiever which is a calculated field as follows:
=IIF(
(Fields!Completeness.Value = 1) AND
(Fields!DateFinished.Value <= Parameters!prmDateFrom.Value) AND
(DateDiff(DateInterval.Day,Fields!DateFinished.Value,Fields!DatePlannedEnd.Value) < 91)
,"Achiever",(
IIF((Fields!Completeness.Value = 2) OR (IsNothing(Fields!Completeness.Value)) AND
(Fields!DateFinished.Value <= Parameters!prmDateFrom.Value) AND
(DateDiff(DateInterval.Day,Fields!DateFinished.Value,Fields!DatePlannedEnd.Value) < 91)
,"Continuing","No/Untimely Achievement")))
Apologies for starting this reply in comments, new to site. Any help is much appreciated.