Advertisement
chusiang

Last 10 record and Sort (Sub-Query)

Jan 15th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.37 KB | None | 0 0
  1. /*
  2.  * 1. select last 10 record and sort.
  3.  * 2. calc (`rowsA` + `rowsB`) / `rowsC`.
  4.  * 3. use Sub-Query.
  5.  */
  6.  
  7. SELECT `record_time`, `tmp` FROM (
  8.  
  9.     SELECT
  10.     `record_time`,
  11.     round(((`rowsA` + `rowsB`) / (SELECT rowsC FROM tableB WHERE bid = '1') * 100), 2) AS 'tmp'
  12.     FROM tableA ORDER BY `record_time` DESC LIMIT 10
  13.  
  14. ) AS `lab_last_10_sort` ORDER BY `record_time` ASC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement