PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 6, 2022

[FIXED] How to count existing field combinations in SQLIte

 October 06, 2022     counting, sqlite, statistics     No comments   

Issue

In a table I have two fields, an aircraft type code and a serial number. I'd like to count how many times a combination of these exist in the table. As aircraft sometimes get reregistered doubling is unavoidable. Is there a method that I can use to see how many times combinations of the same field combinations are present? The query (if possible) should produce a list of some fields and the number of occurences the combination is present in the table. Can this be done?


Solution

A simple aggregation query should do here:

SELECT aircraft_code, serial_num, COUNT(*) AS cnt
FROM yourTable
GROUP BY aircraft_code, serial_num;

But this would return all combinations, including those which only appear once. If you instead want to flag combinations which appear in duplicate, we can add a HAVING clause:

SELECT aircraft_code, serial_num, COUNT(*) AS cnt
FROM yourTable
GROUP BY aircraft_code, serial_num
HAVING COUNT(*) > 1;


Answered By - Tim Biegeleisen
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing