小美是一所中學的資訊科技老師,她有一張 seat 座位表,平時用來儲存學生名字和與他們相對應的座位 id。
其中縱列的 id 是連續遞增的
小美想改變相鄰倆學生的座位。
±--------±--------+| id | student |
±--------±--------+
| 1 | abbot |
| 2 | doris |
| 3 | emerson |
| 4 | green |
| 5 | jeames |
±--------±--------+
假如資料輸入的是上表,則輸出結果如下:
±--------±--------+
| id | student |
±--------±--------+
| 1 | doris |
| 2 | abbot |
| 3 | green |
| 4 | emerson |
| 5 | jeames |
±--------±--------+
select *
from (select id - 1 as id, student
from seat
where id%2 = 0
union
select id + 1 as id, student
from seat
where id%2 = 1
and (id + 1) <= (select count(*) from seat)
union
select id as id, student
from seat
where id%2 = 1
and (id + 1) > (select count(*) from seat)) as t1
order by id asc;
select (case
when mod(id, 2) = 1 and id = (select count(*) from seat) then
idwhen mod(id, 2) = 1 then
id + 1
else
id - 1
end) as id,
student
from seat
order by id;
找出每個部門工資前三高的員工。
select d.name as department,e.name as employee,e.salary as salary
from employee as e
inner join department as d
on e.departmentid = d.id
where (
select count(distinct salary)
from employee
where salary > e.salary
and departmentid = e.departmentid
) < 3
order by e.departmentid,salary desc;
擴充套件:sql的left join 、right join 、inner join之間的區別
left join(左聯接)返回包括左表中的所有記錄和右表中聯結字段相等的記錄
right join(右聯接)返回包括右表中的所有記錄和左表中聯結字段相等的記錄
inner join(等值連線)只返回兩個表中聯結字段相等的行
交換性別
update salary
set*** = case ***
when 'm' then 'f'
else 'm'
end;
shell指令碼
4.統計詞頻
awk ') \|[0-9]\-\)[0-9]\-[0-9]\$' file.txt
6.輸出文字的第十行內容
awk 'nr==10' file2.txt
SQL語句練習
建立一張表,記錄 呼叫員的工作流水,記錄呼叫員編號,對方號碼,通話開始時間,結束時間。建表,插資料等都自己寫出sql 要求 輸出所有資料中通話時間最長的5條記錄。輸出所有資料中撥打長途號碼 對方號碼以0開頭 的總時長 輸出本月通話時長最多的前三個呼叫員的編號 輸出本月撥打 次數最多的前三個呼叫員的編...
SQL 語句練習
mysql select from persons limit 5 oracle select from persons where rownum 5 select from persons where name like l select from persons where name not l...
SQL語句練習
1 把兩張 的資料抽取出來放到另外一張 中 1 pt表 role id int pt int 2 season score表 role id int season score int 3 player表 role id int pt int season score int count int 4 ...