Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQL queries are sorted by specified fields

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

city_name is the field name, now press ("Beijing","Shanghai","Guangzhou") To sort out the data in sequence? Do not know what database you have, if it is Oracle:select count(city_name), city_name from tuan_info where source_type = 1 and city_name in("Beijing","Shanghai","Guangzhou") group by city_nameORDER BY INSTR ('Beijing, Shanghai, Guangzhou', city_name); ORDER BY CHARINDEX(city_name, 'Beijing, Shanghai, Guangzhou') if SQL Server

questioning

SQL Server, how to write oh, give a complete point statement, okay?

answer

select count(city_name), city_name from tuan_info where source_type = 1 and city_name in("Beijing","Shanghai","Guangzhou") group by city_nameORDER BY CHARINDEX(city_name, 'Beijing, Shanghai, Guangzhou') The SQL in front is the same ah. Just add an ORDER BY sort process.

questioning

[SQL] select count(city_name), city_name from tuan_info where source_type = 1 and city_name in("Beijing","Shanghai","Guangzhou") group by city_name ORDER BY CHARINDEX(city_name, 'Beijing, Shanghai, Guangzhou');[Err] 1305 - FUNCTION data_group.CHARINDEX does not exist

answer

What kind of database is this? CHARINDEX is a SQL Server function.

questioning

That, that's MYSQL, what should I do?

answer

MySQL changes a function. INSTRselect count(city_name), city_name from tuan_info where source_type = 1 and city_name in("Beijing","Shanghai","Guangzhou") group by city_nameORDER BY INSTR ('Beijing, Shanghai, Guangzhou', city_name)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report