Say I have the following table in MS SQL Server: Make Model Year Honda Accord 1997 Honda Accord 1997 Honda Accord 1997 Honda Civic 2001 Honda Civic 2005 Honda Civic 2005 Toyota Corolla 2010 Nissan Pathfinder 1997 I want to be able to retrieve the count for the unique combination and get the results like the following: Make Model Year
Tag: distinct
How to select distinct value from multiple tables given a column filter?
I have this table Products Id ProductName ProductCode 1 Alexa P0001 2 Alexa P0002 3 Alexa 2 P0003 4 Aquarium P0004 5 Aquarium X P0004 6 Bathtub P0005 Scenario 1: Expected Result: Returns distinct ProductName along with Id Id ProductName 1 Alexa 3 Alexa 2 4 Aquarium 5 Aquarium X Actual result: Returns all product name starting with ‘A’ distinct
SQL query to fetch distinct values from same table
Let’s say I have this table: employeetable: empid joindate location HRupdatedate Changes 1 2002-01-05 Delhi 2021-03-01 New 2 2009-09-09 Mumbai 2021-03-05 New 1 2010-06-27 Hyderabad 2021-03-03 Transfer 2 2015-11-02 Delhi 2021-03-06 Transfer 3 2020-01-01 Mumbai 2021-03-06 New 4 2007-07-30 Delhi 2021-03-04 New I want to get data from this table where empid in (1,2,4). That will return: empid joindate location
Select Last Rows with Distinct Field
I have a table with the following schema: In this table only the id field is unique. I’m concerned with getting the rows containing the last X distinct itemid, ordered by date. For example, in the sample above, if I’d like to get the last 3 distinct itemid, I’d be getting the first 4 rows, since in the first 4
I am trying to use SQL to count the number of rows for each date in my database
My database is something like this: I only need the counts of the dates like this: I’ve tried … … but the date format is not my friend. Any ideas would be appreciated. Answer In most databases, you can remove the date component by converting to a date and using group by: However, various databases also have other methods to
How can I use select count (distinct x) in order to count two values in the same table and get the the two distinct values in my output?
I am trying to use count (distinct) in order to count the number of distinct values for two different values in the same table. The output I am trying to get should have both of the distinct values as …
DISTINCT work differntly in MYSQL & POSTGRESQL
I have created a sample table report in SQL and filled sample data in it using the following command. I need to find the list of recently visited(based on date column) branches with out duplication. So I used the following query It works on MYSQL but shows the following error on POSTGRESQL. How to fix this? Or How can I
Joining rows and columns in SQL
Current Result: ID | Item | Red | Green | Blue | Yellow 03 balloon 1 0 0 0 03 balloon 0 1 0 0 03 balloon 1 0 0 1 24 ribbon …
Finding daily registered users
I have a table which includes the information of player_id, first_timestamp, last_timestamp, and date, etc. So I have initially 10 payers on 2020-07-08, and then 18 players on 2020-07-09, some of the players from previous day might appear on 2020-07-09 again. And I’m trying to find the new players registered on 2020-07-09 that did not appear on 2020-07-08, but I
SQL count number of records in one set of data compared to another and present as a percentage
I would like to count the number of unique records not matching on 2 key variables from Data B compared to Data A and present the result as a percentage of the total unique records in Data B. Data A: …