關於mysql查詢 關於MYSQL 查詢

2021-10-19 04:50:39 字數 1399 閱讀 9960

你想要的是這種效果嗎?

--建立表city_cost

create table city_cost(id int primary key auto_increment, cost_time date, city varchar(20), money int) auto_increment = 1;

--插入資料

insert into city_cost(cost_time, city, money) values (str_to_date('2018-08-06', '%y-%m-%d'), '武漢', 260);

insert into city_cost(cost_time, city, money) values (str_to_date('2018-08-07', '%y-%m-%d'), '武漢', 400);

insert into city_cost(cost_time, city, money) values (str_to_date('2018-08-08', '%y-%m-%d'), '武漢', 190);

insert into city_cost(cost_time, city, money) values (str_to_date('2018-08-04', '%y-%m-%d'), '南京', 310);

insert into city_cost(cost_time, city, money) values (str_to_date('2018-08-05', '%y-%m-%d'), '南京', 450);

insert into city_cost(cost_time, city, money) values (str_to_date('2018-08-07', '%y-%m-%d'), '南京', 700);

insert into city_cost(cost_time, city, money) values (str_to_date('2018-08-10', '%y-%m-%d'), '北京', 1000);

--查詢表city_cost

--建立檢視v_city_cost

create view v_city_cost(日期, 城市, 消費) as select cost_time, city, money from city_cost;

--查詢檢視v_city_cost

select * from v_city_cost order by 日期 asc;

mysql思考7 關於Uber選擇MySQL的思考

在資料庫圈子,大家都知道今年uber幹出來一件大事件,把postgresql切換到了mysql,當時社群裡一陣喧嘩。事情已經過去半年多了,這裡我不想去和大家再次討論這兩個關係型資料庫那個更好。只是想帶著大家思考一下選擇的背後。在該事件中,uber提出來遷移的乙個重要原因是 在大量更新的業務場景下po...

mysql 關於切分查詢

對於大查詢有時需要 分而治之 將大查詢切分為小查詢 每個查詢功能完全一樣,但只完成原來的一小部分,每次查詢只返回一小部分結果集。刪除舊的資料就是乙個很好地例子。定期清理舊資料時,如果一條sql涉及了大量的資料時,可能會一次性鎖住多個表或行,耗費了大量的系統資源,卻阻塞了其他很多小的但重要的查詢。將乙...

mysql關於unicode編碼查詢

在實際開發中,很多時候我們需要儲存一些表情emojit或者特殊符號,這個時候如果你單純去獲取使用者帶有表情包的名稱資料去儲存時,資料庫儲存儲存會出現亂碼,所以我們在儲存前需要對使用者的資料進行unicode編碼後再儲存,獲取的時候再進行unicode轉碼顯示即可。但是由於轉碼後的資料在資料庫中儲存的...