美文网首页后端
数据库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

    )

    相关文章

      网友评论

        本文标题:数据库sql语句

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