I created the query below but there's no way I have been able to return only the highest value from the column b.new_versionnumber
. Whatever is the highest value on that column, I want to return all the rows that contain that highest value.
SELECT
a.new_AdjustmentAmount as Adjustment_Amount,
a.new_adjustmenttype as Adjustment_Type,
a.new_baseprice as Base_Price,
a.new_price as Net_Price,
a.new_optionidid as Product,
a.new_price as Price,
a.new_locationid as Location_ID,
f.smx_name as Lab_Name,
f.smx_addressstreet1 as Address,
f.smx_city As City,
f.smx_stateprovince as State,
f.smx_country as Country,
a.new_productconfigurationid as Product_Configuration,
a.new_quoteid as Quote_ID,
a.new_quantity as Quantity,
b.new_cpqstatus as Product_Configuration_Status,
b.new_name as Product_Configuration_Name,
b.new_quoteid as Quote_ID,
c.new_approvalstage as Approval_Stage,
c.new_acquisitiontype as Acquisition_Type,
c.new_dealcolor as Deal_Color,
c.new_financing as Finance,
c.new_grossprofit as Gross_Profit_Percentage,
c.new_hybridcpr as Hybrid_CPR_Type,
c.new_leaseintrestrate as Lease_Interest_Rate,
c.new_terms as Lease_Months,
c.new_leaseresidual as Lease_Residual,
c.new_leasetype as Lease_Type,
c.new_printtype as Print_Type,
c.new_totalinstrumentprice as Total_Instrument_Price,
c.new_totalinterfaceallowance as Total_Interface_Allowance,
c.new_totalreagentprice as Total_Reagent_Price,
c.new_totalserviceprice as Total_Service_Price,
c.new_quoteid as Record_ID,
c.new_name as Name,
c.new_totalamount as Net_Amount,
c.new_acquisitiontype as Acquisition_Type,
c.new_approvalstage as Approval_Stage,
c.new_name as Quote_Name,
c.new_opportunityid as Opportunity,
c.new_printtype as Print_Type,
c.new_totalamount as Total_Amount,
c.new_isprimary as Is_Primary,
c.new_opportunityid as Opportunity_ID_Reference,
d.closeprobability as Probability,
d.transactioncurrencyid as Currency,
d.customerid as Account,
d.estimatedclosedate as Estimated_Close_Date,
d.estimatedvalue as Estimated_Revenue,
d.name as Name,
d.ownerid as Account_Manager,
d.smx_contractsoldtoaddress as Sold_To,
d.smx_multisite as Multi_Site,
d.statuscode as Status,
d.totalamount as Total_Amount,
e.smx_description as Product_Description,
e.smx_family as Product_Family,
e.smx_name as Name,
e.smx_producttype as Product_Type,
b.new_versionnumber
FROM
new_cpq_lineitem_tmp a
JOIN
new_cpq_productconfiguration b ON a.new_productconfigurationid = b.new_cpq_productconfigurationid
JOIN
new_cpq_quote c ON b.new_quoteid = c.new_cpq_quoteid
JOIN
opportunity d ON c.new_opportunityid = d.opportunityid
JOIN
smx_product e ON a.new_optionid = e.smx_productid
JOIN
smx_address f ON a.new_locationid = f.smx_addressid
WHERE
e.smx_producttype = '180700001'
GROUP BY
b.new_versionnumber,
a.new_AdjustmentAmount,
a.new_adjustmenttype,
a.new_baseprice,
a.new_price,
a.new_optionidid,
a.new_price,
a.new_locationid,
f.smx_name,
f.smx_addressstreet1,
f.smx_city,
f.smx_stateprovince,
f.smx_country,
a.new_productconfigurationid,
a.new_quoteid,
a.new_quantity,
b.new_cpqstatus,
b.new_name,
b.new_quoteid,
c.new_approvalstage,
c.new_acquisitiontype,
c.new_dealcolor,
c.new_financing,
c.new_grossprofit,
c.new_hybridcpr,
c.new_leaseintrestrate,
c.new_terms,
c.new_leaseresidual,
c.new_leasetype,
c.new_printtype,
c.new_totalinstrumentprice,
c.new_totalinterfaceallowance,
c.new_totalreagentprice,
c.new_totalserviceprice,
c.new_quoteid,
c.new_name,
c.new_totalamount,
c.new_acquisitiontype,
c.new_approvalstage,
c.new_name,
c.new_opportunityid,
c.new_printtype,
c.new_totalamount,
c.new_isprimary,
c.new_opportunityid,
d.closeprobability,
d.transactioncurrencyid,
d.customerid,
d.estimatedclosedate,
d.estimatedvalue,
d.name,
d.ownerid,
d.smx_contractsoldtoaddress,
d.smx_multisite,
d.statuscode,
d.totalamount,
e.smx_description,
e.smx_family,
e.smx_name,
e.smx_producttype
Already tried Max
, Having
, etc.... none worked.