I need to put data from the SQL query into a Pandas dataframe. Please tell me is it possible to get column names the query results? I found that there is a keys() function in sqlalchemy for that but it does not work for me: AttributeError: ‘CMySQLCursor’ object has no attribute ‘keys’ …
Tag: mysql
How do I properly optimize this query?
I’m trying to optimize the following query. I’ve used EXPLAIN to troubleshoot but it keeps showing up in our logs as a non-indexed query. What am I missing? I’ve created indexes on all columns referenced, but it’s still showing up. Answer If you have a big table which contains millions…
Sql Query to obtain unique values from a mixed data
I am new to MySql and have been trying to learn it for a project. I have a table as below (Table 1) and I need the output from it as Table 2. The output is ordered by CREATED_AT field and if there are multiple rows for the same FRUIT_TYPE, the field with the least CREATED_AT value is picked. For
MySQL to Microsoft SQL Server derived table syntax
I am trying to select data from a derived table created in the FROM statement. I have the following code in MySQL: I’m trying to do the same in Microsoft SQL Server, but this doesn’t work, with an error ‘incorrect syntax’. I’ve tried a few different combinations, and anything I c…
How do I sort a table with non alphabetical values?
I’m a non-programmer and want to use the power of SQL to sort my inventory data. Here’s the sample table that I have. I want to turn this data to this. How can I query my table to have a result like this below Answer These two suggestions – if stick to the datasets given. If you’re on …
Simplest method for declaratively applying a SQL schema to a table?
Goal: I’m looking for a declarative and repeatable way of “applying” SQL table schemas to a database What I’ve tried Below is a SQL script that does what I want (as best as I can tell from my superficial knowledge of MySQL and with some manual testing): If the table doesn’t exist…
Create a query to select data from MYSQL WHERE min(i_status) = 4
I Have two MY SQL tables OrderTable and itemTable Im recive all orde whit query1 -ResultTable1 – it ok ResultTable1 but I need to receive all orders, goods with which have a minimum status of 4, and the sum of all goods from this order, not only goods with ID = 4 My query should look like this, but it
Trying to do basic subtraction from a database table
I’m trying to subtract data based on user input, for example: UPDATE table SET quantity=quantity – * some input value* This is easy if I’m subtracting field by field, where id=1…2…3, but I want to subtract values automatically when I input quantity, so if input is 60, and there i…
Get Rows that are include one many to many. but not another
I am having a little trouble with this query. I want to filter my Features down for all features that have applicabilities that have include the name ‘G6’, but that also do not have a many to many relationship with applicabilies that have the name ‘n2’. I have right now: I have a many …
SQL query to group items with their quantity then show a total quantity
I have the following data that I’d like to rearrange using an SQL query: I’d like to group the same order_id to show it like the following: 99996 | 63 – 2, 62 – 2 | 4 So that’s looking for the items in the same order, showing the product id and quantity, then showing the total of…