美文网首页后端
数据库sql语句

数据库sql语句

作者: avery1 | 来源:发表于2018-08-06 14:54 被阅读0次

IN 操作符

http://www.w3school.com.cn/sql/sql_in.asp

SELECT column_name(s)

FROM table_name

WHERE column_name IN (value1,value2,...)

SQL SELECT DISTINCT 语句

http://www.w3school.com.cn/sql/sql_distinct.asp

SELECT  DISTINCT  Company FROM Orders

AND 和 OR 运算符

http://www.w3school.com.cn/sql/sql_and_or.asp

SELECT * FROM Persons WHERE FirstName='Thomas'ANDLastName='Carter'

BETWEEN 操作符

操作符 BETWEEN ... AND 会选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。

日期格式

2009-01-22 21:22:22

2009-01-22 19:21:11

2009-01-22 23:10:22可以省略时分秒

SELECT column_name(s)

FROM table_name

WHERE column_name

BETWEEN "2018-01-10"  AND  "2018-10-10"

SQL JOIN

http://www.w3school.com.cn/sql/sql_join.asp


SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo

FROM Persons, Orders

WHERE Persons.Id_P = Orders.Id_P

SELECT Apps.id, Apps.displayName, Apps.state, Categories.id, Categories.first FROM Apps

INNER JOIN AppCategories ON Apps.id = AppCategories.appId

INNER JOIN Categories ON Categories.id = AppCategories.categoryId

WHERE Apps.state = 'Published' AND AppCategories.categoryId IN

(SELECT Categories.id FROM Categories WHERE Categories.type = "Solution Area")

三表

SELECT Apps.id, Apps.displayName, Developers.displayName AS developer, Apps.state, Categories.first AS SolutionArea FROM Apps

INNER JOIN AppCategories ON Apps.id = AppCategories.appId

INNER JOIN Categories ON Categories.id = AppCategories.categoryId

INNER JOIN Developers ON Apps.developerId = Developers.id

WHERE Apps.state = 'Published' AND Categories.type = "Solution Area"

ORDER BY Apps.id

四表联表查询

SELECT DISTINCT Apps.id, Apps.displayName, Developers.displayName AS developer, Apps.state FROM Apps

INNER JOIN AppCategories ON Apps.id = AppCategories.appId

INNER JOIN Categories ON Categories.id = AppCategories.categoryId

INNER JOIN Developers ON Apps.developerId = Developers.id

WHERE Apps.state = 'Published' AND Categories.type = "Solution Area"

ORDER BY Apps.id

去重

获取report

SELECT Apps.id, Apps.displayName, Developers.displayName AS developer, Apps.state

FROM Apps

INNER JOIN Developers ON Apps.developerId = Developers.id

WHERE Apps.state = "published"

AND Apps.id NOT IN

(SELECT DISTINCT appId FROM AppCategories WHERE AppCategories.categoryId in

(SELECT id FROM Categories WHERE Categories.type = "Solution Area"))

获取admin

SELECT b.fullName, b.email, c.displayName AS developer, a.admin FROM DeveloperProfileMembers AS a

INNER JOIN UserCache AS b ON a.user = b.customerNumber

INNER JOIN Developers AS c ON a.developerId = c.id

WHERE a.admin = 1 AND a.state = "Approved"  AND a.developerId IN

(

SELECT DISTINCT Developers.id AS developer 

FROM Apps

INNER JOIN Developers ON Apps.developerId = Developers.id

WHERE Apps.state = "published"

AND Apps.id NOT IN

(SELECT DISTINCT appId FROM AppCategories WHERE AppCategories.categoryId in

(SELECT id FROM Categories WHERE Categories.type = "Solution Area"))

)

ORDER BY c.displayName

update

UPDATE appvmwareproducts SET vmwareProductId =

(

(

SELECT * FROM

(

SELECT id FROM vmwareproducts WHERE shortName = "vcns" AND version =

(

SELECT version FROM (

SELECT version, COUNT(*) AS count FROM vmwareproducts WHERE shortName = "vcns"

GROUP BY version

HAVING count > 1) a

)

) b  LIMIT 1

)

)

WHERE vmwareProductId = 

(

SELECT * FROM

(

SELECT id FROM vmwareproducts WHERE shortName = "vcns" AND version =

(

SELECT version FROM (

SELECT version, COUNT(*) AS count FROM vmwareproducts WHERE shortName = "vcns"

GROUP BY version

HAVING count > 1) a

)

) b ORDER BY id DESC LIMIT 1

)

DELETE FROM vmwareproducts WHERE id =

(

SELECT * FROM

(

SELECT id FROM vmwareproducts WHERE shortName = "vcns" AND version =

(

SELECT version FROM (

SELECT version, COUNT(*) AS count FROM vmwareproducts WHERE shortName = "vcns"

GROUP BY version

HAVING count > 1) a

)

) b ORDER BY id DESC LIMIT 1

)

相关文章

  • 12.1KOA mysql 数据库

    mysql 数据库 安装 mysql 模块 使用数据库连接执行 SQL 语句 使用数据库连接池执行 SQL 语句

  • SQL分类

    1.SQL语句的分类 DDL语句(数据定义语句)主要用于定义数据库对象的SQL语句数据库对象:表(table),列...

  • SQL语句的分类

    1.SQL语句的分类 DDL语句(数据定义语句)主要用于定义数据库对象的SQL语句数据库对象:表(table),列...

  • 第2章 SQL语句的分类和DML语句

    1.SQL语句的分类 DDL语句(数据定义语句)主要用于定义数据库对象的SQL语句数据库对象:表(table),列...

  • SQL预编译

    1.数据库预编译起源 (1)数据库SQL语句编译特性:数据库接受到sql语句之后,需要词法和语义解析,优化sql语...

  • 数据库SQL语言入门(二)

    系列文章: 数据库SQL语言入门(一)数据库SQL语言入门(三) DDL语句 常用的SQL语句关键字有 creat...

  • MySQL数据库编写SQL语句利器---mycli

    MySQL数据库的操作是利用SQL语句完成SQL语句的操作。 对于初学者,学习SQL语句是操作数据库的必经之路,但...

  • SQL语句的分类

    ### 1.SQL语句的分类 * DDL语句(数据定义语句) 主要用于定义数据库对象的SQL语句 *数据...

  • 数据库SQL语句

    数据库之SQL语句(二) 数据库之SQL语句(一)[https://www.jianshu.com/p/460e3...

  • 黑马 Oracle数据库 百度网盘分享

    01-Oracle数据库-第01天(SQL语句) 02-Oracle数据库-第02天(SQL语句) 03-Orac...

网友评论

    本文标题:数据库sql语句

    本文链接:https://www.haomeiwen.com/subject/rsvuuftx.html