I have the following MySQL table named Table1 The Result can either be Pass or Fail. I want to calculate the percentage pass for each id. Result must be the following table based on formulae: For each id, count Pass / Total Counts for given id. For example id 2 have 2 pass and 2 fail therefore percentage pass…
Tag: mysql
How to correctly convert SQL rows to columns?
Before someone mentions it, I have seen the exact same SQL question on Stack before and from my point of view, that’s actually transposing columns to rows. What I’m trying to accomplish is as seen below in the photos, given the top one, I want to create a new table with the previous data that is f…
Why DB Browser have an order I can’t replicate?
I have an issue I really don’t understand. In fact, I have a database of movies where there’s a table for actors,containing two colums (movie id and name). For example, then I enter the movie id of …
What could cause MySQL to intermittently fail to return a row?
I have a MySQL database that I am running very simple queries against as part of a webapp. I have received reports from users starting today that they got an error saying that their account doesn’t …
Making cumulative sum with ids and dates in MySQL
Imagine I have this: id transactiondate transactiontag clientid transactionvalue 1 2020-12-28 pizza 0 29.99 2 2020-12-29 payment 0 -39.99 3 2020-12-28 cheese 0 -109.99 4 2020-12-28 cheese 0 -109.99 5 2020-12-28 pizza 1 -19.99 6 2020-12-28 cheese 1 -18.99 7 2020-12-28 salary 1 58.99 8 2020-12-29 salary 1 38.99…
insert same record multiple times based on the given count
I want to insert ABC thrice, EDC four times, FDC twice in a table using single SQL, is it possible? The output of the query should insert into the following table with the following entries. Thanks Answer You would typically use a recursive query: Here is a demo; the syntax works in both Postgres and MySQL 8.…
Case statment with join-sql
I have a table User which has many messages and many contacts. The relation between messages and contacts table is made trough contactMessages table. Table messages has a foreign key on contactMessages which is the message_id Table contacts has a foreign key on contactMessages which is the contact_id Each mes…
Select from multiple tables with group and join
i have 4 tabels drinks, opskrifter, ingredients and stock the tables consist of drinks drink_id name beskriv glas image alcohol opskrifter drink_id ingredient_id quantity ingredients ingredient_id name stock ingredient_id name i want a query to select drinks that can be made in opskrifter of the ingredients i…
Generate date from sunday except the existing value, in 1 Week Range
This is the result of my query right now with data getting 1 result only. This is my query: $merid=20; I am trying to populate to get the dates the full week beginning Sunday except the existing Tuesday . Can someone give guidelines on where to begin? Is the logical process can be done here in SQL or do I
mysql 8 pivot query should return a non null value
I would like the following pivot query to show value 0 instead of null, Output for the above is, Employee id 122 does not have a Repayment value so the desired output is, dbfiddle Answer I don’t see the need for the second branch of the repayment case. If you want 0 when the category is not available, j…