mysql(2)

來源:互聯網
上載者:User

標籤:

1.建立計算欄位:

   concat ,    select concat(vend_name,‘(‘,vend_country,‘)‘) from vendors;

   Rtrim,     刪除右側空格

   select a+b as c from table order by c;

2.資料處理函數:

   文本處理函數:upper   ex: select upper(a) as a_upper_case from table;

                    trim,rtrim,trim

                    left  ,    ex: select left(‘abcdefg‘, 3), 返回abc

                    locate:   返回字串str第一次出現的子串SUBSTR的位置 ,ex: select locate(‘a‘,‘bac‘);  得到2

                   substring:  http://www.yiibai.com/sql/sql_function_substring.html

   時間:欄位為datetime類型,儲存為 日期+時分秒,通過date,time函數過濾欄位

                   ex: select xx from table date(xxx)=‘2015-01-01‘;

                   year,month,day過濾出年月日

  資料處理: ex : select Pi();  select rand(); select abs(-1);

3.聚集合函式:avg , 忽略null的欄位)

                  count ,count(*) 不管是否為空白,還是null;count(column)對特定列中具有值進行計算

                 max,min,sum

4.group by ,  ...from table where xxx group by xxx order by xxxx

                處聚聚計算語句外,select語句中的每個列都必須在group by 字句中給出

 

  having xxx ,必須使用運算式,不可使用別名,ex: 如下 不可使用having ordertotal

 

  ex, select order_num,sum(quantity*item_price) as ordertotal

        from orderitems

        group by order_num

        having sum(quantity*item_price)>=50

        order by ordertotal;

    ps: 對 orderitems中的資料,根據order_num 分組,每組計算sum(quantity*item_price),

         當 sum(quantity*item_price)>=50時,過濾出來,按照ordertotal升序顯示

     

      select student_id,avg(score)  as average_score from scores

      group by student_id having avg(score)<60

      order by average_score;

     

mysql(2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.