問題:
乙個表有三列,
a,b,c 請用
sql語句實現
如下功能:如果a
列大於b
列,選擇
a列,否
則選擇b
列;如果
b列大於c列,
選擇b列,否則選擇
c列,用
sql語
句如何實現?
建表:
drop table if exists `comparetable`;
create table `comparetable` (
`id` int(11) not null auto_increment,
`name` varchar(12) default null,
`moneys1` int(11) default null,
`moneys2` int(11) default null,
`moneys3` int(11) default null,
primary key (`id`)
) engine=myisam default charset=utf8;
insert into `comparetable` values (1,'zhang',3000,5200,6300);
insert into `comparetable` values (2,'wang',5000,5200,4000);
insert into `comparetable` values (3,'li',4000,1600,2300);
sql:
select id, name, (case when moneys1 > moneys2 then moneys1 else moneys2 end) as moneysstart,
(case when moneys2 > moneys3 then moneys2 else moneys3 end) as moneysend from comparetable;
SQL面試題 (二)
sql面試題 二 有一張工資表,包含三列 員工編號 id 部門編號 groups 工資 salary 1.找到每個部門工資最高的人 包括並列第一 2.找到每個部門工資最高的人 只選乙個 sql語句如下 declare g table id int,groups nvarchar 20 salary ...
sql 查詢面試題
表中有a b c三列,用sql語句實現 當a列大於b列時選擇a列否則選擇b列,當b列大於c列時選擇b列否則選擇c列 if object id testtb is not null drop table testtb gocreate table testtb a int b int c int in...
SQL問題(面試題)
面試完後在本地mysql資料庫中重現了該問題 資料表stuscore資訊如下 1 計算每個人的總成績,並且排名 要求顯示字段 學號 姓名 總成績 select stuid as 學號,name as 姓名,sum score as 總成績 from stuscore group by stuid o...