city_name是字段名,现在要按("北京","上海","广州") 先后顺序把数据查询统计出来?
不知道你什么数据库, 假如是 Oracle: select count(city_name), city_name from tuan_info where source_type = 1 and city_name in("北京","上海","广州") group by city_name ORDER BY INSTR('北京,上海,广州', city_name); 如果是 SQL Server 用 ORDER BY CHARINDEX(city_name, '北京,上海,广州')
追问
是SQL Server 的,怎么写哦,给个完整点的语句好吗
回答
select count(city_name), city_name from tuan_info where source_type = 1 and city_name in("北京","上海","广州") group by city_name ORDER BY CHARINDEX(city_name, '北京,上海,广州') 前面的SQL都是一样的啊。 只是 增加一个 ORDER BY 的排序处理。
追问
在吗,不行的,提示有错啊,是什么问题哦 [SQL] select count(city_name), city_name from tuan_info where source_type = 1 and city_name in("北京","上海","广州") group by city_name ORDER BY CHARINDEX(city_name, '北京,上海,广州'); [Err] 1305 - FUNCTION data_group.CHARINDEX does not exist
回答
你这个是什么数据库啊? CHARINDEX 是 SQL Server 自带的函数啊。
追问
那个,,是MYSQL的哦,怎办
回答
MySQL 就换一个函数 INSTR select count(city_name), city_name from tuan_info where source_type = 1 and city_name in("北京","上海","广州") group by city_name ORDER BY INSTR( '北京,上海,广州', city_name)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。