0

Query:

 SELECT purchased_profileid, 
        COUNT(distinct(purchased_profileid)) as 'NoofPurchases', 
        final_paidprice  
   FROM MMBMembership mmb, 
        MMB_BusinessProfiles mmbProfiles, 
        basic_details bd, 
        orderdetails_purchasedProfiles odpp
   WHERE mmb.mmb_id = mmbProfiles.MMB_id
     AND mmb.Profile_id = LTRIM(bd.profile_id)
     AND odpp.purchased_profileid = bd.profile_id
     AND mmb.mmb_id = 1
     AND ispublished = 'true'
GROUP BY final_paidprice, purchased_profileid

Result:

purchased_profileid  NoofPurchases  final_paidprice
------------------------------------------------------
10                   1              314.828012285208
10                   1              788.635686407162
11                   1              926.007854252126
11                   1              1000
11                   1              1385.59720636606

How should I modify this query to give me the output as

purchased_profileid  NoofPurchases  final_paidprice
----------------------------------------------------
10                   2              1103.462
11                   3              3311.597

1 Answer 1

3
select purchased_profileid, count(*) as 'NoofPurchases', sum(final_paidprice)  from MMBMembership mmb, MMB_BusinessProfiles mmbProfiles, basic_details bd, orderdetails_purchasedProfiles odpp
where mmb.mmb_id = mmbProfiles.MMB_id
and mmb.Profile_id = ltrim(bd.profile_id)
and odpp.purchased_profileid = bd.profile_id
and mmb.mmb_id = 1
and ispublished='true'
group by  purchased_profileid
Sign up to request clarification or add additional context in comments.

2 Comments

@Scorpio0: it is giving me a "Incorrect syntax near the keyword 'group'. pointing towards the last line "group by purchased_profileid"
@Sun - I'm not sure why you would be getting that. Did you original query run ok? I'd have to see the table definitions for all the tables used in your query to be able to determine what the problem could be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.