LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2011, 06:22 AM   #1
edomingox
Member
 
Registered: Mar 2009
Posts: 64

Rep: Reputation: 16
psql command - how do you combine 2 searches into one command line


I'm trying to figure out how to run the two following commands simultaneously:

Code:
1.    psql -U user myDB -c "select city, count(1) as total_people
 from list where time_up > '2011-05-12 05:00:00' and time_up < 
 '2011-05-12 06:00:00' group by city order by city;"

2.    psql -U user myDB -c "select city, count(1) as 
total_people_with_no_car from list where car is null and time_up > 
'2011-05-12 05:00:00' and time_up <  '2011-05-12 06:00:00' group by 
city order by city;"

Then I hope to show the following:

city    |  total_people_with_no_car  | total_people
----------------------------------------------------
Miami   |                 3232       |     35345
Denver  |                 4234       |     83883
Chicago |                 4445       |     82834
numbers don't mean anything, but you get the idea. Is it even possible to do this?

Last edited by edomingox; 05-13-2011 at 01:01 AM. Reason: corrected statement. should use "city" instead of "ssn"
 
Old 05-12-2011, 08:28 AM   #2
sunnydrake
Member
 
Registered: Jul 2009
Location: Kiev,Ukraine
Distribution: Ubuntu,Slax,RedHat
Posts: 289
Blog Entries: 1

Rep: Reputation: 61
something like this but there is other ways.
mysql> SELECT a.*,b.* FROM (SELECT id from jos_banners_categories) as a,(SELECT id from jos_banners) as b;
+----+----+
| id | id |
+----+----+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
+----+----+
3 rows in set (0.00 sec)
 
Old 05-12-2011, 09:12 AM   #3
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
I presume you have 1 table that in your example would have the following fields:
Code:
ssn (index ?)
time_up
city
car
...
Given that here's the query that will give the amount of people where the car <> '' and the total; the other one I leave for you as an exercise ;-)

Code:
select (select count(*) from "lq-psql" where not car = '') as withcar, count(*) from "lq-psql" as total;
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 11:21 AM
psql : command not found. michelle02012007 Linux - Server 1 07-23-2009 07:15 AM
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 06:30 PM
xine command line? or some other command line only engine? lumix Linux - Software 2 08-10-2007 10:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration