my table looks something like this i have a function, which return 1to3 int value representing effect1,effect2,effect3 and “id” i am trying to increment value of each effect by 1 when my function’s returning “id” matches the “id” from my dataset otherwise creates new …
Tag: mysql
How to get calculated data from one column in database
im new in sql. I cannot get data with format what i want in one step. Now i’m using more sql commands. I want to get all data in one command because i cant to connect them in subquery with group by. Somebodys can help me? example of Table i have: id order_id order_status 1 1 0 2 1 0
MYSQL how to merge rows with same field id into a single row
I have a select statement with rows as table_Schema I need to merge the rows such that blogs with same row id are merged into a single row. I am trying to get either <author fname, author mname, author lname | coauthor fname coauthor lname> or a column as author co author Each blog can have multiple aut…
Percentage based on another column, with group by
This is what I have: getting this one: I want to have additional column, telling me per day how much is my success rate. E.g. 210/(210+40) for day 5, 40/(32+40) for day 6 etc: Answer This way you can get the rates (success/failure) for equivalent status type. Output:
How to count if the difference of two consecutive rows is greater than 0?
Suppose the following table, The final output I am trying to achieve is, where Change is a counter which increments given the difference between any two consecutive rows (value rows) is not 0. How may I achieve this using mysql? Answer LAG() can be used to fetch the preceding row: LEAD() can give the same res…
What does default do in CHARACTER SET and COLLATE when creating a database?
The mysql docs tell me that you can optionally specify DEFAULT for these two lines, but what does it actually do? How is DEFAULT CHARACTER SET different from CHARACTER SET? (The same goes for collate) Answer There’s no difference. They do the exact same thing, whether you use the DEFAULT keyword or not.…
How to structure my database model for a simple web application and organize my SQL data model
I am working on a web app. I have a question about the SQL parts. I am currently creating a food rating interface. The user should be able to login and then rate the food. Currently I use a custom database (users) for the login page. I also use a separate database (review) for the reviews. my current database…
The Sum of people that have same age in SQL?
I’m taking a SQL class and I need help with a question. I have the following table on a phpmyadmin server with a total of 100 patients I’m told to find the sum of people that have same age using SQL. I wrote this query: but it returns 100 as a result and when I did this query and found
Select records in one table and specific matching records from the other
I have three tables, two of which are relevant for this question. Users, Things, User_to_thing Users User_to_thing I’m trying to create a query where I can select all the active users in the users table and have a column where I can see the status for “thing 3” from the User_to_thing table w…
Group by the specific day, month, and year
I have a table as follow, now I use the group by date and it only group my data based on the year. I want to group the data based on the specific day, month, and year. Do you know how we can do that? Answer Use: Check for more info