Jan 31, 2016

Issues when reinstall phpbrew on OS X EI Capitan

Annoying things coming one by one.

After update to EI Capitan, I found that all my configuration for linking phpbrew with system apache lost. Resolved quickly, but...

After did 'brew update' today, phpbrew poisoned by new version of icu4 installed by homebrew. It was built with 54, but now version is 56, so it always complained about could not find the so file...even when change a directory, just because the 'source ~/.phpbrew/bashrc' in my own .bashrc.

At last, I decided to CLEAN all this messed stuff up, via... rm -rf ~/.phpbrew.

And prepared to reinstall it, not be aware of what was waiting for me....

Issue#0 operation not permistted when 'sudo chmod -R oga+rw /usr/libexec/apache2'
  root cause: Apple's system integrity protection
  solution: reboot, cmd+r to enter repair mode, open terminal, execute 'csrutil disable; reboot'
  reference: http://stackoverflow.com/questions/32659348/operation-not-permitted-when-on-root-el-capitan-rootless-disabled

Issue#1 Cannot find OpenSSL's <evp.h>
  root cause: openssl header file missing
  solution: $phpbrew ...+openssl=/usr/local/opt/openssl
refernce: https://github.com/phpbrew/phpbrew/issues/612

Issue#2 Cannot find OpenSSL's libraries
  root cause: openssl lib path missing
  solution: $sudo ln -s /usr/local/opt/openssl /usr/lib/openssl
  reference: https://github.com/phpbrew/phpbrew/issues/418

Issue#3 Cannot locate header file libintl.h
  root cause: gettext header file missing
  solution: $brew link icu4c gettext --force
  refernce: https://github.com/phpbrew/phpbrew/issues/453

Issue#4 symbols not match when php build sis linking:
  Undefined symbols for architecture x86_64:
  "_PKCS5_PBKDF2_HMAC", referenced from:
      _zif_openssl_pbkdf2 in openssl.o
  "_TLSv1_1_client_method", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  "_TLSv1_1_server_method", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  "_TLSv1_2_client_method", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  "_TLSv1_2_server_method", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  root cause: ???
  solution: run following command before phpbrew install: $export LDFLAGS="/usr/local/opt/openssl/lib/libssl.dylib /usr/local/opt/openssl/lib/libcrypto.dylib"
  referenc: http://weaponsgradecode.com/2015/10/12/installing-php-5-6-14-with-phpbrew-and-homebrew-on-os-x-el-capitan/

Finally, my new php-5.6.17 was installed under phpbrew with the following command:
phpbrew install 5.6.17 +default +mysql +pdo +apxs2=/usr/sbin/apxs +dba +filter +gettext +iconv +mcrypt +openssl=/usr/local/opt/openssl +posix +session +soap +sqlite +gd -- --with-gd=shared --enable-gd-natf --with-jpeg-dir=/usr --with-png-dir=/usr

Final thought: it came to my mind at last that homebrew suggest similar method as LDFLAGS config when install some module like openssl. So it might be a compile flag setting which could solve the openssol <evp.h> issue....but anyways, I don't want to try that myself.

Dec 25, 2015

Resolved issue aborting test with jasmine via PhantomJS

Weird issue when executed:

grunt test

I got:
...
Running "concurrent:ts_test" (concurrent) task

        Running "jasmine:ts_dist" (jasmine) task
        Testing jasmine specs via PhantomJS

        Warning: Cannot read property 'pid' of undefined Use --force to continue.

        Aborted due to warnings.
...

After googling solution, found a way work around:

cd node_modules/phantomjs/
npm install

Jasmine working again then.

Oct 16, 2015

Install zmq extension to phpbrew

phpbrew doesn't (seems) support zmq in its official extension list.

Have to find a way around this issue.

Firstly, turn off phpbrew
  phpbrew off

Now using system php.

Next, upgrade system php to 5.6:
  sudo add-apt-repository ppa:ondrej/php5-5.6
  sudo apt-get update
  sudo apt-get install python-software-properties
  sudo apt-get update
  sudo apt-get install php5

Now, install zmq:
  sudo pecl install zmq-beta

After zmq.so created, copy it to the phpbrew directory:
  sudo cp /usr/lib/php5/20131226/zmq.so ~/.phpbrew/php/php-5.6.6/lib/php/extensions/no-debug-non-zts-20131226/zmq.so

Bingo! Now I can composer require react/zmq under my project!!

Links:
http://www.dev-metal.com/install-setup-php-5-6-ubuntu-14-04-lts/

Jun 1, 2015

Solved phpbrew problem with posix function not found

This morning apache complained to me that:

  posix_geteuid() function not found

So weird, because I installed this php version definitely with posix enabled, via phpbrew.

So I installed again:

sudo -s
phpbrew init -c config.yaml
phpbrew install 5.3.29 +dev (i have predefined a dev shortcut in the config file for convenience)
...
phpbrew switch 5.3.29
exit
sudo service apache2 restart

Not working....

So I decided to do it manually instead, guessing the config file not configuring phpbrew very fitting.


phpbrew install 5.3.29 +default +mysql +pdo +apxs2=/usr/bin/apxs2 +dba +filter +gettext +iconv +mcrypt +openssl +posix +session +soap +sqlite +gd -- \
--with-libdir=lib/x86_64-linux-gnu --with-gd=shared --enable-gd-natf --with-jpeg-dir=/usr --with-png-dir=/usr

This time the installed php version working.

So my guess is correct.

ps, the content in my config.yaml:

variants:
    dev:
        bcmath:
        bz2:
        calendar:
        cli:
        ctype:
        dba:
        dom:
        fileinfo:
        filter:
        gettext:
        ipc:
        iconv:
        json:
        mbregex:
        mbstring:
        mhash:
        mcrypt:
        mysql:
        openssl:
        pdo:
        posix:
        session:
        soap:
        sqlite:
        gd:
          - --with-libdir=lib/x86_64-linux-gnu
          - --with-gd=shared
          - --enable-gd-natf
          - --with-jpeg-dir=/usr
          - --with-png-dir=/usr
extensions:
    dev:
        xdebug: stable
        yaml: stable
        curl: stable
        gd: stable

Jan 9, 2015

解决 phpbrew gd 的 undefined symbol: php_gd_gdImageJpegCtx in Unknown on line 0

Issues coming one after one, started from the day I upgrade my machine from ubuntu 12.04 to 14.04.

Thanks to our ancient symfony 1.4 project, I had to ask phpbrew for php version 5.3.x, and then I got a problem with gd when project rebuild on the step of regenerating avatars.

It said in bloody color:

The image processing library GD is not enabled. See PHP Manual for installation instructions.

WTF?

I checked the extensions of current php:

  $phpbrew ext

Oh well, gd ext not enabled, so

  $phpbrew ext enable gd

However, it complained:
 
PHP Warning:  PHP Startup: Unable to load dynamic library '/home/htsg/.phpbrew/php/php-5.3.29/lib/php/extensions/no-debug-non-zts-20090626/gd.so' - /home/htsg/.phpbrew/php/php-5.3.29/lib/php/extensions/no-debug-non-zts-20090626/gd.so: undefined symbol: php_gd_gdImageJpegCtx in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/home/htsg/.phpbrew/php/php-5.3.29/lib/php/extensions/no-debug-non-zts-20090626/gd.so' - /home/htsg/.phpbrew/php/php-5.3.29/lib/php/extensions/no-debug-non-zts-20090626/gd.so: undefined symbol: php_gd_gdImageJpegCtx in Unknown on line 0
===> Enabling extension gd
gd extension is not installed. Suggestions:
$ phpbrew ext install gd

Damn it, how could it suggest to install an extension already installed, sth wrong with it definitely....

Googling time....... with painful tries...ruined my whole lovely friday morning....

When it turned to be hopeless, found a working solution:

$cd
$cd .phpbrew/build/php-5.3.29/ext/gd/
$make clean
$phpbrew ext install gd -- --with-libdir=lib/i386-linux-gnu --with-gd=shared --enable-gd-native-ttf --with-jpeg-dir=/usr --with-png-dir=/usr

This time it said install ok as before, but I saw gd in the enabled list when check extensions.

Thanks to this link for saving the rest of my Friday!






Jan 5, 2015

Solved the PHPunit not found problem after updated it by composer

PHPUnit now supports installation via composer:

$sudo composer global require "phpunit/phpunit=4.4.*"
$sudo composer global require "phpunit/phpunit-selenium"
$sudo composer global require "phpunit/dbunit"

But before installation, you would have to uninstall them via phear:

$sudo pear uninstall phpunit/PHPUnit_MockObject  \
 phpunit/PHP_CodeCoverage \
 phpunit/DbUnit \
 phpunit/PHPUnit_Selenium \
 phpunit/PHPUnit \
 phpunit/PHP_Timer \

However, symfony phpunit task lost its link to phpunit after above operations.

sh: 1: phpunit: not found

I had to link phpunit to /usr/local/bin, seems a temporary solution:

sudo ln -fs /home/ACCOUNT/.composer/vendor/bin/phpunit /usr/bin/phpunit

Reference links:
https://github.com/sebastianbergmann/phpunit/wiki/End-of-Life-for-PEAR-Installation-Method

Nov 13, 2014

解决eclipse4.3.1 ctrl click不工作的问题

升级eclipse到Kepler(4.3.1)之后,发现ctrl+click函数声明追踪不好使了,股沟了一下,原来是dltk的数据库版本不向下兼容:

!ENTRY org.eclipse.dltk.core.index.sql 4 0 2013-10-14 16:45:28.670
!MESSAGE An exception has thrown while performing a search
!STACK 0
org.h2.jdbc.JdbcSQLException: 
Unsupported database file version or invalid file header in file "Old database: 
/home//workspace/.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2/model.data.db 
- 
please convert the database to a SQL script and re-create it." [90048-168]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)

解决办法:

关闭eclipse,把workspace/.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2/目录下的文件全部删除,再打开eclipse,它会自动重建声明索引数据库。

PS,期间遇到“workspace in use or cannot be created”的问题,到workspace/.metadat/目录下,删除.lock文件,轻松解决。

Sep 28, 2014

解决ubuntu 14.04下安装phpmyadmin失败

Problem:

Try to re-install phpmyadmin on ubuntu 14.04, got error:

  dpkg: error processing package phpmyadmin (--configure):
 子进程 已安装 post-installation 脚本 返回了错误号 1
在处理时有错误发生:
 phpmyadmin
E: Sub-process /usr/bin/dpkg returned an error code (1)

Root cause:

"该错误通常发生在以下情况,使用 dpkg -i安装deb包后,直接删除了程 序所有相关的目录和文件,但是 dpkg库中仍然保留了该程序的相关 信息。 因此,当执行apt命令时,dpkg自检 时便会发现相关文件丢失,于是报 出标题中的错误。"

Solution:

解决方法如下:

#检查当前 dpkg库中残留的文件安装信息
dpkg -l | grep phpmyadmin

 #手 动删除所有包,这一步可能仍然会 有相关错误信息报出
sudo dpkg -r phpmyadmin

#这一 步很重要,彻底清除任何****包相 关的信息
sudo dpkg -P phpmyadmin

dpkg -l | grep phpmyadmin

应该就没 有任何错误信息了,再执行其它安 装程序,也不会报错了。

now run:

sudo apt-get install phpmyadmin

success!

参考链接:

http://tiankonguse.com/record/record.php?id=272

Aug 7, 2014

How to set default env to develop for symfony project

After you created a symfony project, including frontend app, when visit the local site url of the project, you would do want it showing the symfony debug toolbar by default.

This means you don't need to append frontend_dev.php to visit the develop env.

Following tricks on site definition do help on this:

1. Edit your apache virtual host definition for the project website, add this line:

SetEnvIf Request_URI ".*" PROJECT_ENV=dev

So your virtual host configuration will look like:

<VirtualHost localhost:80>
  ServerName yoursite.localhost
  ServerAlias *.yoursite.localhost *.yoursite.local-site
  DocumentRoot "__your_symfony_project_doc_root__"
  DirectoryIndex index.php

  # Set the project environment mode: dev, prod
  # Note: This is a bit of hack because SetEnv won't let var values show up in rewrite conditions.
  SetEnvIf Request_URI ".*" PROJECT_ENV=dev

  <Directory "__your_symfony_project_doc_root__">
   AllowOverride All
   Allow from All
  </Directory>
  Alias /sf "__your_symfony_project_path__/lib/vendor/symfony/data/web/sf"
  <Directory "__your_symfony_project_path__/lib/vendor/symfony/data/web/sf">
   AllowOverride All
   Allow from All
  </Directory>
</VirtualHost>

2. Edit your project website .htaccess file as below, attention to bold lines:

# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks +ExecCGI
Options +SymLinksIfOwnerMatch +ExecCGI

<IfModule mod_rewrite.c>
  RewriteEngine On

 # For testing setting the project env, uncomment next line.
#  SetEnvIf Request_URI ".*" PROJECT_ENV=prod


  SetEnvIf Host prod\..* PROJECT_ENV=prod

  # uncomment the following line, if you are having trouble
  # getting no_script_name to work
  #RewriteBase /

  # we skip all files with .something
  #RewriteCond %{REQUEST_URI} \..+$
  #RewriteCond %{REQUEST_URI} !\.html$
  #RewriteRule .* - [L]

  # we check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f

  # no, so we redirect to our front web controller

  # Below we define conditional rules that will go controller based on env
  # The default will be dev.

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{ENV:PROJECT_ENV} =prod [NC]
  RewriteRule ^(.*)$ index.php [QSA,L]

  #RewriteCond %{ENV:PROJECT_ENV} =dev [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ frontend_dev.php [QSA,L]
</IfModule>

3. Restart apache service, enjoy your developing!

May 22, 2014

Ubuntu下解决Chrome升级后界面中文乱码问题

Ubuntu版本:12.04 LTS

昨天Chrome升级到35后,包括书签,Tab,地址框,以及右键菜单中的中文都变成乱码。

尝试用用以下方法解决:

sudo ln -s ../conf.avail/69-language-selector-zh-cn.conf /etc/fonts/conf.d/69-language-selector-zh-cn.conf

不起作用,查看了该文件的内容,与参考链接给的模板文件不太一样。

删除链接文件,下载编辑模板文件,重命名为69-language-selector-zh-cn.conf,拷贝覆盖原文件。

重启Chrome,依然不起作用。

注销重新登录,无变化,晕啊。

今天早上又股沟了一下,原来需要把系统的字体改一下:

Settings Manager > Appearance > Fonts > Default Font

改成 WenQuanYi Micro Hei

重启Chrome,问题解决, 耶!哈哈哈。

其实把系统的语言支持设置为中文(排到第一位),也能解决此问题,但系统整个变成中文化环境,不适合工作需要。


参考链接:
https://code.google.com/p/chromium/issues/detail?id=335651

May 19, 2014

Upgrade to Ubuntu 14.04 failed on my 2012 late iMac

I should not click 'Yes' while it prompted 'A new version found, do you want to upgrade.'

The whole upgrade process seemed ok, only except some compile errors about out of memory with fontconf....

But at the end of upgrade, it reported the upgrade failed, and it could not roll back to the old 13.04.

I reboot the machine into ubuntu anyway, it brought up everything, and seems a new version already installed, only that the desktop resolution abit low.

But i wouldn't bother myself to figure that out, since I don't know what other potential issues there. Don't want to take any risk and put myself into a even worse situation.

So, after googling a little, I decided to give it a fresh installation with 14.04, for sake of it's a LTS version.

And shame that couldn't find image for mac on ubuntu official download site, finally found it from a forum:

http://cdimage.ubuntu.com/releases/trusty/release/ubuntu-14.04-desktop-amd64+mac.iso
(MD5: 0bc7243aacd5f80f8110dcf3165dffd0)

Downloading now, and hope no other issues with the installation upcoming...

May 12, 2014

Linux bash history with Page up / Page down

n linux you can configure the pgup/pgdown keys to navigate through commands you typed that begin with the string you just typed. Type "mysql" and then hit "Page up", and you will see nothing but mysql-related commands.
Unfortunately this has to be configured anew on every machine or server/vm I work on, and I always forget where this is configured (and it takes a while to find it in google), so I thought I should write it down.
------------
In /etc/inputrc, uncomment:
# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Restart your shell or use Ctrl+X, Ctrl+R to tell it to re-read.
(thanks stackoverflow)
Yep, it's not ".bashrc" but "inputrc".
Not sure why this one is not hidden, but so it is.
You could try ~/.inputrc for a local, user-specific configuration.
Tried this in Ubuntu, and it works.

Add alias and color to git

edit your git config  /home/%youraccount%/.gitconfig as following

[alias]
   st = status
   ci = commit
   br = branch
   co = checkout
   df = diff
   lg = log -p
   lol = log --graph --decorate --pretty=oneline --abbrev-commit
   lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
   ls = ls-files
   meld = !/usr/local/bin/git-meld.pl
[merge]
   tool = meld
[mergetool]
   keepBackup = false
[merge "ours"]
   driver = true
[mct "review"]
   command = git meld
[color]
   ui = true
[color "diff"]
   whitespace = red reverse
[core]
   whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol
[color]
   ui = auto
[color "branch"]
   current = yellow reverse
   local = yellow
   remote = green
[color "diff"]
   meta = yellow bold
   frag = magenta bold
   old = red bold
   new = green bold
[color "status"]
   added = yellow
   changed = green
   untracked = cyan
[user]
   name = Fan Deng
   email = leondeng@gmail.com
[diff]
   tool = meld

May 2, 2014

Screen brightness setting with Xfce on iMac, iMac Xfce 屏幕亮度调节

1. 键盘亮度调节支持
默认安装xfce后没有安装(xfce4-power-manager-plugins)的插件,在ububtu下面 apt-get install xfce4-power-manager-plugins安装后启动一下power manager工具即可通过键盘调节亮度

2. 屏幕亮度记忆
屏幕亮度不能保存,每次开机都回恢复到最亮的状态。
请教了Google后,在一个外文博客上发现了解决的方法。
首先要写一个调节屏幕亮度的脚本,只有一句:
echo 3 > /sys/class/backlight/acpi_video0/brightness
里面的“3”可以替换为1-10中任意数字,越大越亮。
把这个脚本保存起来,比如保存为~/brightness
把这个脚本移动到/usr/local/sbin/brightness,并增加运行的权限
chmod +x /usr/local/sbin/brightrness
接着,配置允许不输入密码就sudo运行这个脚本,运行visudo,增加下面这行:
# User privilege specification
syndim        ALL=NOPASSWD: /usr/local/sbin/brightness
将上面的syndim替换为用户名。
最后,打开Applications  > Xfce Settings  > Session and startup,将
sudo /usr/local/sbin/brightness
添加进去,重新启动,enjoy~
参考链接:

Dec 20, 2013

Upgrade (and keep synced with system update) git version on ubuntu 12.04

My git version was 1.7.9.5, while the latest version is 1.8.5.2, wanted to upgrade it to use the --diff-dir option available from version 1.7.11.

Tried the way of download source code and build locally (https://www.digitalocean.com/community/articles/how-to-install-git-on-ubuntu-12-04), not working for me.

Finally, found this page:

and steps are:

1. add git ppa
$sudo add-apt-repository ppa:git-core/ppa
2. update
$sudo apt-get update
3. upgrade git
$sudo apt-get install git

Check version with command
$git --version
git version 1.8.5.2

Yeah~

Dec 6, 2013

[Resolved] Eclipse 4.3.1 has no PHP perspective after PDT installed

Last night I installed Eclipse 4.3.1 on my iMac under ubuntu 13.10, all good till I found that no matter how I tried, Eclipse wouldn't show out the PHP perspective. The PHP perspective even did not exist in Window->Open Perspective->Other... dialogue.

This made me a bit crazy.

However, finally, here is the dramatic end of the story.

After struggling with uninstall/reinstall several versions of several plugins, and searched online, no luck though. But one thread made me thought about the permission of the path I installed Eclipse, /opt/eclipse.

Then I entered in plugins folder in that path, no PDT plugin found there, and no CDT plugin I installed for testing either. Then this came to a 99 percent fact that it was a permission issue.

Think I could install PDT again under sudo executing eclipse, but I chose another way, installed another eclipse 4.3.1 in user folder this time, ~/ide/eclipse, where I have full privilege.

And the ending was happy.

Although it was my stupid, and this story maybe not worth telling, but considering I almost gave it up, and there was not any really helpful clue online, so I tell it out here.

Cheers and good night~~

Dec 5, 2013

Install PDT 3.1.1 on Eclipse 3.7 (Indigo)

At first, when I tried to install PDT 3.1.1 on Eclipse 3.7 (Indigo), there was an error that a dependency software missing: DLTK 4.0.

It recalled me about the similar issue when I tried to install ShellED, a bash editor plugin of Eclipse, last month.


While I couldn't update DLTK from Indigo repository:


  http://download.eclipse.org/releases/indigo/

Or

  http://download.eclipse.org/technology/dltk/updates/

But there's a link for the nightly build on DLTK's page http://www.eclipse.org/dltk/install.php

I tried this link in Eclipse install new software dialogue window, this time it returned all DLTK 4.0 packages, wonderful!

After DLTK 4.0 installed, just install PDT 3.1.1 via this source in the installation dialogue:

  http://download.eclipse.org/tools/pdt/updates/release

and finally, as a frosting on the cake, I installed ShellED via this soource:

  http://sourceforge.net/projects/shelled/files/shelled/update/

Happy happy~~

Nov 1, 2013

郁闷啊,OSX 升级10.9后一周,WiFi找不到了

郁闷。
我的iMac27 2012一周前升了苹果最新的OSX 10.9.0 Maerick后,昨晚突然搜不到家里的WiFi信号了,而其它的设备,包括家里的所有平板,手机,还有我的笔记本(Windows7)都没有问题。
尤其严重的是,试图设置WiFi时,竟然导致系统假死,无限风火轮,甚至连勉强打开的Terminal都无法用键盘输入,程序切换倒还好用。
无奈之下,用时光机恢复了前天晚上的备份,好在这几天都在忙活试图在外置硬盘上给这台iMac装Windows7的事,没有太多需要备份的东西。
恢复之后,倒是不假死了,但是WiFi的问题依旧。
上网查询,原来我并不孤单,网上早已是哀鸿遍野,而且似乎没有什么准灵的解决办法。
难道真的要降回到山狮10.8.5?
今早到公司又查了一下,似乎编辑一下网络的Location可以解决,等回家试一下。

System Preferences -> Network -> Location -> Edit Locations.. -> make a new location, call it anything and then switch to that location and click apply.

另外的招数包括:
1 更改路由器无线设置,改用5G频段 (我的Netgear貌似不支持)
2 还是改路由器无线设置,改为802.1 b n g only (我的Netgear貌似已经是如此)
3 暂时用网线连接,等待苹果解决问题
4 降级,等苹果解决问题之后再升级

最后只能说一句,免费的苹果真的不那么好吃啊。

Jan 4, 2013

Bring PHP core auto-complete back in Eclipse 3.7

Imported a project from git server, found that I could not 'Add PHP Support...' to it to get php core function and keyword auto-complete during coding, it was really annoying...

Finally found this solution on Stackoverflow, it works for me.

1. Open file .buildpath in project root path.
2. Add following lines if there is no <buildpath> section:


<buildpath>
 <buildpathentry kind="src" path=""/>
 <buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
</buildpath>

3. If there is <buildpath> already, just add this line:

<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>

4. Restart Eclipse.

source link: http://stackoverflow.com/questions/1232647/code-completion-assist-for-built-in-php-functions-in-eclipse-pdt

Oct 18, 2012

Do group by after order by in SQL


SELECT * FROM (
SELECT * FROM (
SELECT `m`.`id` AS `m__id`, `m`.`appliedat` AS `m__appliedat`, `m`.`idstudent` AS `m__idstudent`, `m`.`idclass` AS `m__idclass`, `m`.`comment` AS `m__comment`, `m`.`score` AS `m__score`, `m`.`created_by` AS `m__created_by`, `m`.`updated_by` AS `m__updated_by`, `m`.`deleted_at` AS `m__deleted_at`, `m`.`created_at` AS `m__created_at`, `m`.`updated_at` AS `m__updated_at`, `m`.`schoolcode` AS `m__schoolcode`, `c`.`id` AS `c__id`, `c`.`name` AS `c__name`, `c`.`code` AS `c__code`, `c`.`description` AS `c__description`, `c`.`idtype` AS `c__idtype`, `c`.`value` AS `c__value`, `c`.`idroot` AS `c__idroot`, `c`.`lft` AS `c__lft`, `c`.`rgt` AS `c__rgt`, `c`.`level` AS `c__level`, `c2`.`id` AS `c2__id`, `c2`.`name` AS `c2__name`, `c2`.`code` AS `c2__code`, `c2`.`description` AS `c2__description`, `c2`.`idtype` AS `c2__idtype`, `c2`.`value` AS `c2__value`, `c2`.`idroot` AS `c2__idroot`, `c2`.`lft` AS `c2__lft`, `c2`.`rgt` AS `c2__rgt`, `c2`.`level` AS `c2__level`, `c3`.`id` AS `c3__id`, `c3`.`name` AS `c3__name`, `c3`.`code` AS `c3__code`, `c3`.`idroot` AS `c3__idroot`, `c3`.`lft` AS `c3__lft`, `c3`.`rgt` AS `c3__rgt`, `c3`.`level` AS `c3__level`, `c4`.`id` AS `c4__id`, `c4`.`name` AS `c4__name`, `c4`.`code` AS `c4__code`, `c4`.`idroot` AS `c4__idroot`, `c4`.`lft` AS `c4__lft`, `c4`.`rgt` AS `c4__rgt`, `c4`.`level` AS `c4__level` FROM `mark` `m`
INNER JOIN `mark_criteria` `m2` ON (`m`.`id` = `m2`.`idmark`)
INNER JOIN `criteria` `c` ON `c`.`id` = `m2`.`idcriteria`
INNER JOIN `mark_criteria` `m3` ON (`m`.`id` = `m3`.`idmark`)
INNER JOIN `criteria` `c2` ON `c2`.`id` = `m3`.`idcriteria` AND (`c2`.`idtype` = 9)
LEFT JOIN `criteria_type` `c3` ON `c`.`idtype` = `c3`.`id`
LEFT JOIN `criteria_type` `c4` ON `c2`.`idtype` = `c4`.`id`
WHERE (`c`.`id` IN (46, 50) AND `m`.`idstudent` = 50 AND `m`.`idclass` = 12 AND (`m`.`deleted_at` IS NULL) AND ((`m`.`schoolcode` = 12345 OR `m`.`schoolcode` IS NULL)))
ORDER BY `m`.`appliedat` DESC, `m`.`created_at` DESC
) AS T
 GROUP BY `c__id`
) AS T
 ORDER BY `m__appliedat` DESC, `m__created_at` DESC


http://topic.csdn.net/u/20111024/18/4423fd26-60b5-4ed6-b541-16ba38d7356c.html