Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:34:39+00:00 2026-06-09T03:34:39+00:00

I have a query: select e.Owner as ‘Owner’, COUNT(l.EnquiryID) as ‘Total Sales Lines’ from

  • 0

I have a query:

select e.Owner as 'Owner', COUNT(l.EnquiryID) as 'Total Sales Lines'
from DayBookQuoteLines l, DayBookEnquiries e
where l.EnquiryID = e.EnquiryID
and MONTH(e.enquirydate) = 8 and YEAR(e.enquirydate) = 2012 
group by e.Owner

This returns the owner column which contains a name and a total column, but i wish to have two more columns where i apply an additional filter and count again, adding in:

l.LostStatusId =2 

and

l.LostStatusId =3 

So i’ll be left with a result set that looks like something like this:

Owner      Total Lines    Total Sold    Total Lost    

Person1    124            112           12

I cant seem to get the query right. I’m attempting to use sub-selects but am obviously missing something, any assistance would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:34:41+00:00Added an answer on June 9, 2026 at 3:34 am

    You might conditionally count records by adding one when condition is satisfied.

    select e.Owner as 'Owner', 
           COUNT(l.EnquiryID) as 'Total Sales Lines',
           sum(case when l.LostStatusId = 2 then 1 end) TotalSold,
           sum(case when l.LostStatusId = 3 then 1 end) TotalLost
      from DayBookQuoteLines l
     inner join DayBookEnquiries e
        on l.EnquiryID = e.EnquiryID
     where MONTH(e.enquirydate) = 8 
       and YEAR(e.enquirydate) = 2012 
     group by e.Owner
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query: select substr(name,7,50) as location, points,sum(if (p1=r1,10,-10))as total from dq.data group
I have following SQL query: SELECT Count(*) AS CountOfRecs FROM tblAccount INNER JOIN tblAccountOwner
I have the following query: SELECT src_big, created, modified, owner, aid, caption FROM photo
I have a query along the lines of this: SELECT * FROM posts WHERE
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
i have this query: SELECT `completed`.`ID` AS `ID`,`completed`.`level` AS `level`,`completed`.`completed_in` AS `completed_in`, COUNT(1) AS
I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query: SELECT COUNT(*) AS invoice_count, IFNULL(SUM(qa_invoices.invoice_total), 0) AS invoice_total, IFNULL(SUM(qa_invoices.invoice_discount) ,0)
I have a query: SELECT ID FROM requests WHERE date <operator> <expression> I need
select 'Owner' as 'Type', count(s.shipwynum) as Total, o.ownwynum as WYNum, o.ownshortnam as 'Short name',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.