随笔分类 - SQL
摘要:一、SQLAlchemy和Alembic 主要使用原生的SQLAlchemy进行数据库操作和使用Alemic进行数据库版本控制 I 创建数据库主要有三个步骤 创建表的父类/数据库连接/Session 初始化每个表的class定义 class UserBaseModel(): __tablename_
阅读全文
摘要:今天插入一条数据就像这样 然后报错: You can't specify target table 'categorys' for update in FROM clause 不能select同一个表中的某些值,然后update到同一个表中 然后修改如下: 重点在 select a.id from
阅读全文
摘要:索引,MySQL中也叫“键”,是存储引擎中用于快速找到记录的一种数据结构,具体的工作方式就像书本中的索引一样,但是具体的实现方式会有差别。 一.索引分类 B-Tree索引: 优点: MyISAM中,索引根据数据的物理位置引用被索引的行,InnoDB中根据主键引用被索引的行。 B-Tree索引能够加快
阅读全文
摘要:Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. For example, ret
阅读全文
摘要:Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. For example, aft
阅读全文
摘要:The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. The Department table holds all dep
阅读全文
摘要:The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id. The Department table hol
阅读全文
摘要:Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything
阅读全文
摘要:Write a SQL query to find all duplicate emails in a table named Person.
阅读全文
摘要:The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id. Given the Em
阅读全文
摘要:Write a SQL query to find all numbers that appear at least three times consecutively. For example, given the above Logs table, 1 is the only number th
阅读全文
摘要:Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking num
阅读全文
摘要:Write a SQL query to get the nth highest salary from the Employee table. For example, given the above Employee table, the nth highest salary where n =
阅读全文
摘要:Write a SQL query to get the second highest salary from the Employee table. For example, given the above Employee table, the second highest salary is
阅读全文
摘要:Table: Person Table: Address Write a SQL query for a report that provides the following information for each person in the Person table, regardless if
阅读全文

浙公网安备 33010602011771号