码迷,mamicode.com
首页 > 数据库 > 详细

sql-select

时间:2017-05-17 17:20:59      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:ons   not   limit   imp   set   ant   status   apply   order by   

SELECT
    column_1,column_2,...
FROM
    table_1
[INNER|LEFT|RIGHT]JOINtable_2ONconditions
WHERE
    conditions
GROUPBYcolumn_1
HAVINGgroup_conditions
ORDER BYcolumn_1
LIMIToffset,length;

 


 
select语法
 
HAVING 和 WHERE 区别:

The MySQL HAVING clause is often used with the GROUP BY clause. When using with the GROUP BY clause, we can apply a filter condition to the columns that appear in the GROUP BY clause. If the GROUP BY clause is omitted, the HAVING clause behaves like the WHERE clause.

Notice that the HAVING clause applies the filter condition to each group of rows, while the WHERE clause applies the filter condition to each individual row.

 

subquery:

SELECT
    orderNumber, customerNumber, status, shippedDate
FROM
    orders
WHERE
    orderNumber IN (SELECT
            orderNumber
        FROM
            orderDetails
        GROUP BY orderNumber
        HAVING SUM(quantityOrdered * priceEach) > 60000);

 

 

 

sql-select

标签:ons   not   limit   imp   set   ant   status   apply   order by   

原文地址:http://www.cnblogs.com/hong2016/p/6868037.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!