mysql

Importing from Excel to MySQL Table Using Python 2.7

我们两清 提交于 2021-02-08 04:32:41
问题 I'm trying to insert into a MySQL table from data in this Excel sheet: https://www.dropbox.com/s/w7m282386t08xk3/GA.xlsx?dl=0 The script should start from the second sheet "Daily Metrics" at row 16. The MySQL table already has the fields called date, campaign, users, and sessions. Using Python 2.7, I've already created the MySQL connection and opened the sheet, but I'm not sure how to loop over those rows and insert into the database. import MySQLdb as db from openpyxl import load_workbook wb

Importing from Excel to MySQL Table Using Python 2.7

ぐ巨炮叔叔 提交于 2021-02-08 04:32:16
问题 I'm trying to insert into a MySQL table from data in this Excel sheet: https://www.dropbox.com/s/w7m282386t08xk3/GA.xlsx?dl=0 The script should start from the second sheet "Daily Metrics" at row 16. The MySQL table already has the fields called date, campaign, users, and sessions. Using Python 2.7, I've already created the MySQL connection and opened the sheet, but I'm not sure how to loop over those rows and insert into the database. import MySQLdb as db from openpyxl import load_workbook wb

creating column alias using function in mysql?

夙愿已清 提交于 2021-02-08 04:13:41
问题 I have this table sales(productid, sales_date) I want to get the monthly sales count for last 12 month. How can I generate the month name on the column alias (without hard coding)? I tried this :- http://sqlfiddle.com/#!2/ee777/9 But I want the result table in this format productid Oct-12 Nov-12 Dec-12 Jan-13 Feb-13 Mar-13 Apr-13 May-13 1 0 0 3 4 2 8 2 11 2 0 5 6 8 2 0 0 0 I tried to give the column alias using function DATE_FORMAT(sales_date, '%M') but it is syntax error. select productid

laravel belongsToMany Filter

て烟熏妆下的殇ゞ 提交于 2021-02-08 04:10:45
问题 I have three tables as below: users id|name|username|password roles id|name users_roles id|user_id|role_id These tables communicate via belongsToMany. I would like to find a way to select all data in “users” table except ones that their user value of "role_id" is 5 in table “users_roles”. How can I do it? 回答1: You should use whereDoesntHave() to select models that don't have a related model meeting certain criteria: $users = User::whereDoesntHave('roles', function($q){ $q->where('role_id', 5)

laravel belongsToMany Filter

那年仲夏 提交于 2021-02-08 04:10:32
问题 I have three tables as below: users id|name|username|password roles id|name users_roles id|user_id|role_id These tables communicate via belongsToMany. I would like to find a way to select all data in “users” table except ones that their user value of "role_id" is 5 in table “users_roles”. How can I do it? 回答1: You should use whereDoesntHave() to select models that don't have a related model meeting certain criteria: $users = User::whereDoesntHave('roles', function($q){ $q->where('role_id', 5)

creating column alias using function in mysql?

久未见 提交于 2021-02-08 04:07:40
问题 I have this table sales(productid, sales_date) I want to get the monthly sales count for last 12 month. How can I generate the month name on the column alias (without hard coding)? I tried this :- http://sqlfiddle.com/#!2/ee777/9 But I want the result table in this format productid Oct-12 Nov-12 Dec-12 Jan-13 Feb-13 Mar-13 Apr-13 May-13 1 0 0 3 4 2 8 2 11 2 0 5 6 8 2 0 0 0 I tried to give the column alias using function DATE_FORMAT(sales_date, '%M') but it is syntax error. select productid

Sum Top 10 Values

北慕城南 提交于 2021-02-08 04:05:26
问题 I’ve searched and I know this has been asked before but I am struggling to get my head around what I can / can’t do. My cycling club records race results each time a rider has entered a race. Each result is awarded points - 50 for 1st, 49 for 2nd etc. So the table looks like resultid(pk) | riderid(fk) | leaguepts 1 1 50 2 2 49 3 3 48 4 1 50 5 2 42 6 3 50 7 4 30 ...etc I am trying to extract the sum of top 10 points awarded for each riderid from the results table. (the actual database is a bit

How to determine programmatically MySQL relationship type (1:1, 1:n, n:m) between tables?

穿精又带淫゛_ 提交于 2021-02-08 03:57:14
问题 I'm trying to query a MySQL server to determine information about a database in order to scaffold some code. I've been quite successful using Java JDBC and INFORMATION_SCHEMA table for this but the problem is that I need to determine if a table relation is OneToOne , OneToMany or ManyToMany . I can't find a good way to achieve this and I would love if someone could help me a bit and if its possible with a solution that is not MySQL specific and solid so it could help others. I found this

Laravel 5.4 - Reset Password change “email” column

浪子不回头ぞ 提交于 2021-02-08 03:53:21
问题 I'm working with differing versions of Laravel and have built an addon that uses Laravel 5.4, Which unfortunatley is using a DB that references Laravel 3 sic The " users " table has a column titled " user_email ". On the reset password, I want to change the DB Query to check against "user_email" not "email". As I currently get the error : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' SQL Query that it's trying to run is : SQL: select * from `users` where

How to update a graph using matplotlib

泄露秘密 提交于 2021-02-08 03:48:53
问题 I'm using Panda and matplotlib to draw graphs in Python. I would like a live updating gaph. Here is my code: import matplotlib.pyplot as plt import matplotlib.animation as animation import time import numpy as np import MySQLdb import pandas def animate(): conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="sentiment_index", use_unicode=True, charset="utf8") c = conn.cursor() query = """ SELECT t_date , score FROM mytable where t_date BETWEEN Date_SUB(NOW(), Interval 2 DAY)