您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。