-- 排序
-- 1).ASC(默认)升序,从小大排序
-- 2).DESC降序,从大到小排序
-- 查询表中的所有支出项,结果按照升序排序
SELECT * FROM gjp_ledger WHERE parent = '支出' ORDER BY money;
-- 查询所有收入项,结果按照日期降序排序
SELECT * FROM gjp_ledger WHERE parent = '收入' ORDER BY createtime DESC;
-- 查询所有的'收入项',结果按'金额'升序排序,按'日期'降序排序;
SELECT * FROM gjp_ledger WHERE parent = '收入' ORDER BY money,createtime DESC;
-- 分组查询
-- 一条查询,查询出总收入和总支出;
SELECT
(SELECT SUM(money) FROM gjp_ledger WHERE parent = '支出') '总支出',
(SELECT SUM(money) FROM gjp_ledger WHERE parent = '收入') '总收入';
SELECT parent,SUM(money ) FROM gjp_ledger GROUP BY parent; |
|