面试时遇到的SQL记录
Posted 菜鸟楚
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了面试时遇到的SQL记录相关的知识,希望对你有一定的参考价值。
1.mysql创建表和设置主键
a. CREATE TABLE db (\'id\' VARCHAR(10), \'name\' int(20), \'phone\' VARCHAR(11), \'score\' varchar(10)) PRIMARY key (\'id\');
b. select name, score from db where score in (\'100\', \'60\' \'0\');
2.取某一列的的前18位location:
SELECT
s1.shelf_code,
s3.length,
s3.width,
s3.height,
s3.length * s3.height * s3.width * 0.7 AS slot_V,
s3.open_face
FROM
prime_pmc.shelfs AS s1
LEFT JOIN prime_pmc.shelf_level_item AS s2 ON s1.shelf_id = s2.shelf_id
LEFT JOIN prime_pmc.shelf_item_slot s3 ON s2.level_item_id = s3.level_item_id
WHERE
s1.shelf_code NOT IN (
SELECT DISTINCT
(LEFT(location, 18))
FROM
prime_pmc.inventorys_detail
WHERE
location != \'\'
)
AND s1.level_total_num = \'2\';
3.
select 员工Id ,部门Id,姓名,ifNULL(部门名称,未标志) from tbl_Emloy a left join tbl_Depts b on a.员工id=b.员工is;
以上是关于面试时遇到的SQL记录的主要内容,如果未能解决你的问题,请参考以下文章