joyacv2
asked on
find information in other table
Hi,
I have the following query:
$stid = oci_parse($conn, "SELECT fer, distrito, count(fer),COUNT(CASE WHEN PARC_TOT = 'P' THEN 1 END) COL_P,COUNT(CASE WHEN PARC_TOT = 'T' THEN 1 END) COL_T,COUNT(CASE WHEN (CAUSAS LIKE '%RECE%' OR CAUSAS LIKE '%RECI%') AND PARC_TOT = 'T' THEN 1 END) COL_REC FROM INR WHERE FECHA_REC BETWEEN TO_DATE('2014-01-01','YYYY -MM-DD') AND TO_DATE('2014-02-01','YYYY -MM-DD') GROUP BY fer, distrito ORDER BY count(fer) DESC");
The distrito is a number, but I have a table that contains that table with the name. The table is like that
distrito name
1 lert
2 bcs
3 dffg
how i can change this query to use distrito name and not the number?
I have the following query:
$stid = oci_parse($conn, "SELECT fer, distrito, count(fer),COUNT(CASE WHEN PARC_TOT = 'P' THEN 1 END) COL_P,COUNT(CASE WHEN PARC_TOT = 'T' THEN 1 END) COL_T,COUNT(CASE WHEN (CAUSAS LIKE '%RECE%' OR CAUSAS LIKE '%RECI%') AND PARC_TOT = 'T' THEN 1 END) COL_REC FROM INR WHERE FECHA_REC BETWEEN TO_DATE('2014-01-01','YYYY
The distrito is a number, but I have a table that contains that table with the name. The table is like that
distrito name
1 lert
2 bcs
3 dffg
how i can change this query to use distrito name and not the number?
Please post the CREATE TABLE statements for the table(s) you want to use in the query, thanks.
ASKER
Hi,
I don't have the create table statements, because the tables are already created and i don't have the code, i only have access to the tables, sorry about that
I don't have the create table statements, because the tables are already created and i don't have the code, i only have access to the tables, sorry about that
ASKER
i want to do a vlookup excel function for the distrito field
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
don't work gary, i think that something needs to have a relationship. any other idea?
Learn about SHOW CREATE TABLE queries. I'm sure there is some analog in Oracle.
ASKER
I found the answer add inner join to the gary statement and problem solved! Thanks to all!
If the number in one table is a lookup value in another table that has a value you want, it is a simple table join.
We would need actual table definitions, sample data and expected results for us to write the exact SQL statement you need.
If you are not familiar with joins:
http://en.wikipedia.org/wiki/Join_%28SQL%29
We would need actual table definitions, sample data and expected results for us to write the exact SQL statement you need.
If you are not familiar with joins:
http://en.wikipedia.org/wiki/Join_%28SQL%29
ASKER
thanks for the link!
Focus on the INNER JOIN unless you can have values in the one table that don't exist in the other (then it is an OUTER JOIN).
ASKER
perfect!
thanks again!!!
thanks again!!!