Skip to content
Advertisement

Tag: mysql

Sum columns depending on another column value

I’m having trouble with summing the fields values based on another fields value. I need to SUM(activities.points) based on activities.activity_type if it’s used_points or added_points and put it in AS used_points/added_points. Table activities: Table subscriptions: What I need: What I tried : Which is wrong. Thanks Answer You want to use SUM(IF( )). You want to add up the values

Generate CREATE statements for all MySql Tables

I want All CREATE statements of MySql Tables in 1 query result. For example, INFORMATION_SCHEMA contains all table names,comments etc. but where are the CREATE statements are stored in MySql ? can it be retrieved in one query for all tables ? Currently i am retrieving TABLE ddl as below for 1 table. I have 100’s of tables so i

SQL auto_increment behaviour

My first question is: Can I manually input ID into an auto_increment column of a table? For example: I have 10 records with ID from 1 to 10. Can I manually input the 11 record with the ID of 3 (yes, it’s a duplication!) My second question is: I assume that it’s possible to manually input ID number, what if

Conditional UPDATE in MySQL

I am trying to UPDATE values from a table, but I need to add some conditions. I found the function CASE, but I am not if it is the best method. Here is an example. My table is ‘relation’: userid1 | userid2 | name1 | name2 I got for example: Output: 4 | 3 | bill | jack and I

Advertisement