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

  • Home
  • SEARCH
  • 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 7412009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:28:29+00:00 2026-05-29T06:28:29+00:00

I am very new to SQL and am using SQLite 3 to run basket

  • 0

I am very new to SQL and am using SQLite 3 to run basket analysis on sales data.

The relevant columns are the product ID, a unique transaction ID (which identifies the basket) and the product quantity. Where a customer has bought more than one product type, the unqiue transaction ID is repeated.

I am wanting to count the number of baskets where the customer has bought 1 item.

So far I have tried select count(distinct uniqID) from salesdata having sum(qty) = 1;

But this brought up an error saying a GROUP BY clause is required before HAVING.

I then tried select count(distinct uniqID) from salesdata group by uniqID having sum(qty) = 1

SQlite accepted this, but returned me a list of just 1s, which isn’t right either!

I then tried select count(uniqID) from salesdata group by qty having sum(qty) = 1

SQlite also accepted this but returned nothing at all.

Any ideas would be hugely appreciated!

E

  • 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-05-29T06:28:30+00:00Added an answer on May 29, 2026 at 6:28 am

    Try something like this to retrieve every user which has more or equal than one item in his basket

    select uniqID, sum(qty) as total from salesdata group by uniqID having total >= 1
    

    if you want to have only the users which have 1 item in their baskets replace >=1 with =1

    like:

    select uniqID, sum(qty) as total from salesdata group by uniqID having total = 1
    

    If you want the numbers of users with 1 item in their baskets you get this like this:

    SELECT COUNT(*) FROM (select uniqID, sum(qty) as total from salesdata group by uniqID having total 
    = 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to SQL and am using SQLite 3 to run basket
I've got a sql query (using MS-SQL 2005) that generates data with these columns:
I'm very new to SQL Server. I'm using a cursor to populate a table
I'm very new to using Linq-to-SQL, that's why I'm asking this question. I've searched
Im very new to SQL but need to write a query to do the
Hi I'm very new to sql but have been passed a job in which
I am a very experienced MS Sql developer, and a few new job positions
I still very new using Subversion. Is it possible to have a working copy
Here is one very interesting problem. I am using SQL Server 2008. I have
I am very new to SQL Server. I am trying to determine the best

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.