mysql之常見函式 幾道小題目

2021-09-03 08:15:52 字數 1794 閱讀 8973

mysql之常見函式(幾道小題目)

我就直接po**了

#1.顯示系統時間(注:日期+時間)

select now() as 當前時間;

#2.查詢員工號,姓名,工資,以及工資提高百分之20%後的結果(new salary)

select

employee_id,

last_name,

salary,

salary * (1+0.2) as "new salary"

from

employees ;

#3.將員工的姓名按首字母排序,並寫出姓名的長度(length)

select

last_name,

length(last_name) as 姓名長度,

substr(last_name, 1, 1) as "first"

from

employees

order by `first` asc ;

/*#4.做乙個查詢,產生下面的結果

earns monthly but wants dream salary

king earns 24000 monthly but wants 72000*/#

select

concat(

last_name,

' earns ',

salary,

' monthly but wants ',

salary * 3

) as "dream salary"

from

employees

where salary = 24000 ;

/*#5.使用case-when,按照下面的條件:

job grade

ad_pres a

st_man b

it_prog c

sa_rep d

st_clerk e

產生下面的結果

last_name job_id grade

king ad_pres a*/#

select

last_name,

job_id,

case

job_id

when 'ad_pres'

then 'a'

when 'st_man '

then 'b'

when 'it_prog'

then 'c'

when 'sa_rep'

then 'd'

when 'st_clerk'

then 'e'

end as grade

from

employees

where job_id = 'ad_pres' ;

#limit關鍵字(先感受一下,後面我再說limit)

select * from employees

order by last_name asc

limit 5;

#select * from employees

order by last_name asc

limit 0, 5;

#select * from employees

order by last_name asc

limit 5, 3;

關於scanf函式輸入及小題目回顧

1.a b累加和的計算及scanf函式的輸入 include int main return 0 2.a b的和及scanf函式的特殊結束方式 include int main 輸出a b的和 return 0 3.百錢白雞問題 include int main 4.砝碼稱重問題 小明非常喜愛物理,...

python學習之 小題目 針對快速教程

題目出處 vamei 1.寫乙個程式,判斷2008年是否是閏年。寫乙個程式,用於計算2008年10月1日是這一年的第幾天?2008年1月1日是這一年的第一天 這些小題目是為了方便大家加深對python理解而設計的。def isleapyear year if year 400 0 or year 1...

50道程式設計小題目之 完數

題目 乙個數如果恰好等於它的因子之和,這個數就稱為 完數 例如6 1 2 3.程式設計 找出1000以內的所有完數。因子 就是所有可以整除這個數的數,不包括這個數自身 python解題 a list a str list b list sums 0 sums str for i in range 2...