Tags: SQL python xlwt tablePython writes a database query result to a table experienceDescriptionOperation there are some requirements, in the development of the page before the implementation of this feature, every morning we have to query statements into forms, and then sent to them, it is very annoying ah, in Python wrote a script to achieve this functionFirst
name): Count rows -- SUM (column name): Statistics The contents of rows that meet the criteria and -- AVG (column name): Statistics the column average -- Max, min: Statistical maximum and minimum valuesLimit record Bar number limitsSELECT * from Examresult limit 1;
SELECT * from Examresult limit 2,5; -- Skip the first two entries to show the next five Records
SELECT * from Examresult limit 2, 2;Regular expressionsSELECT * FROM employee WHERE emp_name REGEXP ' ^yu ';
SELECT * FROM e
accessed directly from a key value. That is, it accesses records by mapping key code values to a location in the table to speed up lookups. This mapping function is called a hash function, and the array that holds the record is called the hash table. It can be guessed that the hash table is used for the implementation of the dictionary (dict) type and set (set)
ObjectiveTable tables are often encountered in Web pages, especially in the background operations page. This article explains in detail how table tables are positioned.I. Understanding table1. First look at what the table looks like, for example, this mesh table is table2. The source code is as follows: (Save with txt text, suffix to HTML)No. Second,
Label:Example 1, get MySQL version #-*-coding:utf-8-*-
#installing MySQL DB for Python
Importmysqldb as MDB con=NoneTry:
#ways to connect to MySQL: Connect ( host = ‘localhost‘ ,user = ‘root‘ ,passwd = ‘root‘ ,db = ‘test‘ ,port = 3306 )con = Mdb.connect ('localhost','Root',
'Root','Test'); #all queries that run on the cursor of a module connected to conCur =con.cursor ()#Execute a queryCur.execute ("SELECT VERSION ()")
#Gets the result
) init_db ()View CodeAdd data to the two tables aboveSession = Sessionmaker (bind=engine) Session=Session ()#adding data to the Group tableSession.add (Group (caption='DBA')) Session.add (Group (Caption='SA') ) Session.commit ()#adding data to the user tableSession.add_all ([User (username='User1', group_id=1), User (username='User2', group_id=1), User (username='User3', group_id=2), User (username='User4', group_id=2)]) session.commit ()View CodeTo query all users in the user
Python sequence table Learn a bit, data structure and algorithm, do a summary. If it's not right there, please give me more advice.Sequential tables , in which elements are stored sequentially in a contiguous storage area, the order relationships between elements are naturally represented by their order of storage.A linked list that stores elements in a series of storage blocks constructed from links.The C
In the previous article, we introduced our storage and indexing process, which will introduce SQL queries, single table queries, and TOPN implementations.
One, SQL parsing
Formal SQL parsing is using a parser, but I looked for a long time, only know can use YACC, bison and so on, sqlite use of lemon, pounded the whole day did not implement, the use of the regular expression of Python.
1, delete useless s
I. Installation of XLRD
Address
After downloading, use the pip install .whl installation is good.
View Help:
>>> Import xlrd >>> Help (XLRD) to package Xlrd:name xlrd package CONTENTS BIFFH Book Comp Doc formatting Formula info licences sheet TimeMachine xldate xlsx functions count_records (filename, OUTFILE=L T;idlelib. Pyshell.pseudooutputfile object at 0x0287e730>) dump (filename, outfile=
The above methods allow you to view the XLRD Help information, which contains some modules i
code can start from the ID, convenient.
Insufficient implementation:
In order to prevent the master-slave delay too high, the use of each delete SLEEP1 seconds, relatively rough, the best way should be periodic scan this copy link, according to the delay to adjust the sleep cycle, anyway, scripted, and then intelligent Point why!
The above is a small series to introduce the Python incremental cycle to delete the MySQL
[Spark] [Hive] [Python] [SQL] A small example of Spark reading a hive table$ cat Customers.txt1Alius2Bsbca3Carlsmx$ hiveHive>> CREATE TABLE IF not EXISTS customers (> cust_id String,> Name string,> Country String>)> ROW FORMAT delimited fields TERMINATED by ' \ t ';hive> Load Data local inpath '/home/training/customers.txt ' into
Tags: fetchall nbsp python class set for SEL statement RAM (Create connection and cursor code omitted here) SQL1="SELECT * FROM table name" #SQL statement 1Cursor1.execute (SQL1)#Execute SQL statement 1Read1=list (Cursor1.fetchall ())#reading Results 1Sql2="SHOW full COLUMNS from table name" #SQL Statement 2Cursor1.execute (SQL2)#Execute SQL stat
Because the unit designs the database tables, all use SQL. I don't know what the reason is not to powerdesign or Ermaster tools, to build a table is painful as a program ape of course to find a solution, write a program with Python to solveNeed to use XLRD Linux under sudo pip install xlrdMainly applicable to DB2 databaseThe Excel table structure where number is
before, set charset= ' GBK ', and then the query results directly decode (' GBK ') cannot operate, because the database character set and the table's character set are ' GBK ', so the database link here we must set as ' GBK ', But because we need to get the column name character set by the pit Father's setting to ' latin1 ', so the query returned by the string is actually ' latin1 ' encoded, essentially ' GBK ' of the string, of course, using any kind of decode can not be converted correctly, o
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.