Its so simple. Just need to do below thins: |
SELECT SUBSTRING_INDEX(GROUP_CONCAT(x.id ORDER BY x.nx DESC), ',', 2) as row_name from some_table GROUP BY some_field |
It will select First two values only. |
It total value of GROUP_CONCAT is "1,2,3,4,5" Then Using SUBSTRING_INDEX would be like "1,2" |
You can use DISTINCT in GROUP_CONCAT function like SUBSTRING_INDEX(DISTINCT(GROUP_CONCAT(x.id ORDER BY x.nx DESC)), ',', 2) |
Saturday, December 16, 2017
MYSQL Group Concat Select Some Selected Rows Only | Use Sort In Group Concat | Sort MySQL Rows in Group Concat
Friday, December 8, 2017
Thursday, December 7, 2017
PHP Call Static Function Method Dynamically Based on __callStatic Method
<?php abstract class ParentClass { public static function __callStatic($method, $args) { echo "Method=".$method.",Args=".json_encode($args)."\r\n<BR/>"; } } class ChildClass extends ParentClass { public static function x1() { $args = func_get_args(); call_user_func_array( array(parent::class, __FUNCTION__), $args ); } } ChildClass::x1("x1", 10, 20); ChildClass::x2("x2", 30, 40);
And output would be like:
Method=x1,Args=["x1",10,20] Method=x2,Args=["x2",30,40]
Sunday, December 3, 2017
GRAILS GROOVY | GString Template Engine | Parse Simple String AS GString Template | String GSP Parser
def gEngine = new groovy.text.GStringTemplateEngine() def binding = ["a": "a"] String testVar = gEngine.createTemplate("MY ENGINE STRING AS=\${a}").make(binding).toString() println(testVar)
Saturday, December 2, 2017
jQuery.noConflict() | Avoiding Conflicts with Other Libraries
(function() { function loadJQuery() { var startingTime = new Date().getTime(); var script = document.createElement("SCRIPT"); script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'; script.type = 'text/javascript'; script.onload = function() { var $j = jQuery.noConflict(); jQuery = $; $(function() { var endingTime = new Date().getTime(); var tookTime = endingTime - startingTime; window.alert("jQuery previous version=" + $.fn.jquery + ", version=" + $j.fn.jquery); }); }; document.getElementsByTagName("head")[0].appendChild(script); } loadJQuery(); })();
Check here for JSFiddle
Load jQuery with Javascript and use jQuery | Load jQuery dynamically
(function() { function loadJQuery() { var startingTime = new Date().getTime(); var script = document.createElement("SCRIPT"); script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'; script.type = 'text/javascript'; script.onload = function() { var $ = window.jQuery; $(function() { var endingTime = new Date().getTime(); var tookTime = endingTime - startingTime; window.alert("jQuery is loaded, after " + tookTime + " milliseconds!, version=" + $.fn.jquery); }); }; document.getElementsByTagName("head")[0].appendChild(script); } if (window.jQuery) { alert("JQuery loaded"); } else { alert("JQuery not loaded"); loadJQuery(); } })();
Check here for JSFiddle
GIT | View Changed Details For Files By Commits | View List Of Files Changed During Different Commits
This below command will show changes made during last 3 commits for specific file defined |
git diff HEAD~3..HEAD -- project/location/file.name |
This command will list files changes made during last 3 commits |
git diff --name-status HEAD~3..HEAD |
This command will list files changes made during last 3 commits with changes |
git diff HEAD~3..HEAD |
Below command will show history of commits: |
git log -3 git log -2 |
Below command will show difference between two commits: |
git diff old_commit new_commit git diff 5300b....4ea31a 754e8d....c33 git diff --name-status 5300b....4ea31a 754e8d....c33 |
Subscribe to:
Posts (Atom)