Monday, November 25, 2013

Copy files from remote server

scp -P port user@server:/path_to_the_file/file  /path_to_local_dir/
get file size:
ls -sh file

Monday, November 11, 2013

Select from Many-to-Many with GroupBy

Three entities: 
Cue(id, name) 
Reaction(id, name) 
Freqs(id, cue_id FK, reaction_id FK, some_other_data)

Get most frequent reactions and their frequency:
Select name from rdb_reaction 
where id in (SELECT reaction_id as freq
  FROM rdb_formdata group by reaction_id order by count(*) desc limit 20);


Count number of (cue, reaction) pairs like (cue.name, reaction.name, count):
SELECT distinct
  c.name cue_name,
  b.name reaction_name, 

 (SELECT
  Count(*)
  FROM 
  rdb_freqs a1
  where 
  a1.cue_id =  a.cue_id and 
  a1.reaction_id = a.reaction_id 
  ) as count
FROM 
  rdb_freqs a 
  inner JOIN rdb_reaction b ON a.reaction_id = b.id
  inner JOIN rdb_cue c ON a.cue_id = c.id
  order by count desc