太久没有用SQL语句都有些忘记了,今天工作中遇到了那就尝试记录一下吧 需求是这样的:想查询同一个字段下,两条指定了不同内容,的其他的值 主要是要想到用where......in 语句如下:select * from jac_motorcade_vehicle where vin in ('VSN00001888888888','ZH201807090001002','ZHT00002000020026')
1.查询重复值: select code,count(*) as count from hospital group by code having count>1; 该语句查询code重复值大于1的记录 2.删除重复: DELETE FROM hospital WHERE id NOT IN (SELECT dt.minno FROM (SELECT MIN(id) AS minno FROM hospital GROUP BY code) dt); 该语句保留id最小的记录,其余code重复的
代码如下: $conn = new mysqli('localhost', 'root', '', 'excel');$sql = "select 中信一级行业 from excel group by 中信一级行业 order by convert(中信一级行业 USING gbk) COLLATE gbk_chinese_ci";//按中文排序$query = $conn->query($sql);$firstClass = array();//一类行业总集$result =
首先我们建立一张带有逗号分隔的字符串. CREATE TABLE test(id int(6) NOT NULL AUTO_INCREMENT,PRIMARY KEY (id),pname VARCHAR(20) NOT NULL,pnum VARCHAR(50) NOT NULL); 然后插入带有逗号分隔的测试数据 INSERT INTO test(pname,pnum) VALUES('产品1','1,2,4'); INSERT INTO test(pname,pnum) VALUES('产
select gid, username from users where FIND_IN_SET(8,gid); //查询gid里含有数字8的记录,gid是varchar ,数据格式:"1,12,8,18,5" select gid, username from users where !FIND_IN_SET(8,gid); //查询gid里不含有数字8的记录,gid是varchar ,数据格式:"1,12,8,18,5"
找第一层: SELECT * FROM tourists WHERE json_data->'$.weixinOpenId' = '299485886686868' 或者 SELECT * FROM devices WHERE JSON_EXTRACT(json_data, "$.lcswAccessToken") = '33e5028835bf4d478ed5cd8f8a618ea5' 找多层: SELECT * FROM devices WHERE json_extract(
--SQL查询每个表的字段数量select b.[name], count(*) As AllCount,ISNULL(ISNULL(sum(case when isnullable=0 then 1 end),null),null) as NotNullCountfrom syscolumns aINNER JOIN( select [id], [name] from [sysobjects] where [type] = 'u' ) AS b ON a.id = b.[id] GROUP b
当MySQL查询时排序的字段不是数字时而是汉字的时候也可以用when then 来指定排序. 列如yewu_check表的status 字段不是0,1,2而是汉字待办,已办,退回.可以如下写法: SELECT * FROM yewu_check ORDER BY CASE WHEN STATUS='待办' THEN 2 WHEN STATUS='已办' THEN 1 ELSE 0 END DESC 结果: