HI,
I have a problem to make SQL query which describe below Problem
Table : TbData AutoID | ID1 | ID2 | Status 1 10 1 1 2 10 2 0
3 11 1 1 411 2 1
I want output like this : ID1 | Count(Status(1)) | Count(Status(0)) 10 | 1| 1 11| 2 | 0
How to make query for this ?
I have to solve this problem very urgent so please if u hav any idea regarding this then guide me
thanks in advance
1 2355
I dont think this is a self join. looks like you are simply grouping by ID1 and getting a count of the status. -
[155]dave@> CREATE TABLE t (autoid NUMBER, id1 NUMBER, id2 NUMBER, status NUMBER);
-
-
Table created.
-
-
Elapsed: 00:00:00.09
-
[155]dave@>
-
[155]dave@> INSERT INTO t
-
2 VALUES (1, 10, 1, 1);
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
[155]dave@> INSERT INTO t
-
2 VALUES (1, 10, 2, 0);
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
[155]dave@> INSERT INTO t
-
2 VALUES (1, 11, 1, 1);
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
[155]dave@> INSERT INTO t
-
2 VALUES (1, 11, 2, 1);
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
[155]dave@>
-
[155]dave@> SELECT id1,
-
2 SUM( DECODE(status,
-
3 1, 1,
-
4 0) ) status_1,
-
5 SUM( DECODE(status,
-
6 0, 1,
-
7 0) ) status_0
-
8 FROM t
-
9 GROUP BY id1
-
10 ORDER BY id1;
-
-
ID1 STATUS_1 STATUS_0
-
---------- ---------- ----------
-
10 1 1
-
11 2 0
-
-
Elapsed: 00:00:00.01
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Orion |
last post by:
Hi, This is kind of last minute, I have a day and a half left to figure
this out. I'm working on a project using ms-sqlserver. We are
creating a ticket sales system, as part of the system, I...
|
by: Shahzad |
last post by:
dear respected gurus,
I would like to knew how to apply append,insert query for a self table
where no primary keys issues.
i do have problem say there are 5 rows of single record, this is data...
|
by: deko |
last post by:
I'm trying to update the address record of an existing record in my mdb with
values from another existing record in the same table. In pseudo code it
might look like this:
UPDATE tblAddress SET...
|
by: Jim Andersen |
last post by:
I have a problem with this standard employee-supervisor scenario
For pictures:
http://www.databasedev.co.uk/self-join_query.html
I want to show all employees "belonging" to a specific...
|
by: Paul H |
last post by:
I seem to end up with loads of append and update queries just because it's
quick and easy to build queries or make a new ones based on an existing
query. But I end up with loads of queries with...
|
by: Richard Hollenbeck |
last post by:
I hope this isn't too confusing.
The following query runs pretty fast by itself, but when I want to use it in
a report (pasted below the query), it takes at least fifteen seconds to run!
Then I...
|
by: Genalube |
last post by:
All right I am new at access but why would my calculated fields in my query self destruct all of a sudden? I tested these expressions, saved the query and closed it. I reopened them and tested it. ...
|
by: write2ashokkumar |
last post by:
hi...
i have the table like this,
Table Name : sample
Total Records : 500000 (Consider like this)
Sample Records:
id ------------ name
|
by: write2ashokkumar |
last post by:
hi...
i have the table like this,
Table Name : sample
Total Records : 500000 (Consider like this)
Sample Records:
----------------
|
by: write2ashokkumar |
last post by:
hi...
i have the table like this,
Table Name : sample
Total Records : 500000 (Consider like this)
Sample Records:
----------------
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |