I am trying to create a SQL Query wherein it will pick all distinct records from the first column and do a count of all the items related to that column similar to a countifs command in Excel. I am new to SQL and I am really lost at this point. please help. Sample Table: Employee Item Weight EmpA Red
Tag: sql
Trigger to check if the combination of two field exist
I want to create a trigger which will check if my showtime with Cinema Hall Id exist or not. This will prevent me from booking one Cinema hall at two same Showtimes. Secondly in this trigger I am also checking if the showtime I am assigning to movie lies in movie release and last date range or not. But I
ASP.NET Core display all rows in database on page
I am trying to display every row from a database on a website with ASP.NET Core MVC, but I cannot find any source on how to do it.. This is what Ive tried to do but I got stuck: My Database is structured like this: Id, Username, Password, PasswordHash, but I only want to display Username to begin with. If
How to select only one row if a value of a column occurse multiple times in the result?
I have a table like this on: AttributeA AttributeB AttributeC AttributeD A B EQUALITY D 123 B EQUALITY D 456 B C D … … … … My goal is, to create a Select-Query where the result only contains one row with an equal AttributeC – no matter of the count of rows with the same value in …
Adding a column to an SQL table and exploding the rows with a set of fixed values for that column
I would like to add a column to an SQL table with unknown columns and explode the entries in that table by a set of fixed values for that column. E.g. Turn unknown col 1 … unknown col x 1 … foo 2 … bar into unknown col 1 … unknown col x new col 1 … foo 1 2
SQL Server 2016: how to get a single row view
I have been trying to word this correctly, but here’s my dbfiddle Table: Expected Output: CustomerKey processdate Product_Mix Product_Mix_Expanded 101 2021-05-01 12,3,5 CCcount, CHKCount, SACount 102 2021-02-03 1,3,1 CCcount, CHKCount, SACount 103 2019-04-12 4,0,2 CCount, SACount As you can see, I used …
Count of all occurrences on all rows
I need to complete an overall count of occurrences of one column and all rows. As an example of data: How many times the place has occurred. I’ve done this so far which counts the years but how do I then do a count on that count So how do I now count my places by the year counts? For
MySQL Query – Pending Friends Approval / Relationship between user & friends
I have two tables: g_relationships (id,request_id,receiver_id,status,approved) g_users (which contains: id,username,…) I have a hard time making a query that adds a temporary column, checks whether userid: 4 exists in request_id or receiver_id column, and take the other userid and fetch username from g_…
SQL Case statement with Count?
I have a database that allows for more than one ethnicity per person. Unfortunately, our answers are essentially Yes Hispanic, Not Hispanic, and Unknown, and there are some who do indeed have multiple selections. I need to run a large query that pulls lots of info, one of which is ethnicity, and I want to …
dynamic pivot SQL Query in DB2
I have table like below in DB2 where all these 3 columns are VARCHAR data type I need a dynamic PIVOT query which should select values for ABC_COL1 and ABC_COL2 in row format when FILE_NM filter is used as ABC.TXT The same query should select the values for XYZ_COL1, XYZ_COL2 and XYZ_COL3 in row format when F…