Help create the query
Hi allI have the below requirement.
Master table:
Product ID Product Name
1 TV
2 Cellphone
3 Laptop
4 DVD Player
Details table:
Product ID Spec type Spec Detail
1 Color Blue
1 Weight 20
2 Color Blue
2 Weight 20
3 Color Blue
3 Weight 25
4 Color Blue
4 Weight 20
4 Height 10
I'm looking for a way to identify products with the exact same specifications.That is to say, in the example TV and cell phone above has exact specifications.
So the result of the query must be TV and phone cell phone here.
Is it possible to do in a query, or we need a sql block to perform this action.
Any help would be greatly appreciated.
Thank you
Agathya
Hi agathya,
We do not know how you want to handle the situation where more than two products have the same specifications, so I extended your sample data slightly to take account of this situation as well:
SQL> create table products (id,name)
2 as
3 select 1, 'TV' from dual union all
4 select 2, 'Cellphone' from dual union all
5 select 3, 'Laptop' from dual union all
6 select 4, 'DVD Player' from dual union all
7 select 5, 'Radio' from dual union all
8 select 6, 'VCR' from dual
9 /
Tabel is aangemaakt.
SQL> create table product_specifications (product_id,spec_type,spec_detail)
2 as
3 select 1, 'Color' , 'Blue' from dual union all
4 select 1, 'Weight', '20' from dual union all
5 select 2, 'Color' , 'Blue' from dual union all
6 select 2, 'Weight', '20' from dual union all
7 select 3, 'Color' , 'Blue' from dual union all
8 select 3, 'Weight', '25' from dual union all
9 select 4, 'Color' , 'Blue' from dual union all
10 select 4, 'Weight', '20' from dual union all
11 select 4, 'Height', '10' from dual union all
12 select 5, 'Color' , 'Blue' from dual union all
13 select 5, 'Weight', '20' from dual union all
14 select 6, 'Color' , 'Blue' from dual union all
15 select 6, 'Weight', '20' from dual union all
16 select 6, 'Height', '10' from dual
17 /
Tabel is aangemaakt.
SQL> select p1.name
2 , p2.name
3 from products p1
4 , products p2
5 , product_specifications ps1
6 , product_specifications ps2
7 where p1.id = ps1.product_id
8 and p2.id = ps2.product_id
9 and p1.id < p2.id
10 group by p1.id
11 , p1.name
12 , p2.id
13 , p2.name
14 having sqrt(count(*)) =
15 count(case when ps1.spec_type = ps2.spec_type and ps1.spec_detail = ps2.spec_detail then 1 end)
16 /
NAME NAME
---------- ----------
TV Cellphone
TV Radio
Cellphone Radio
DVD Player VCR
4 rijen zijn geselecteerd.
But why devil you or your specifications product model predecessor like that? You are much more complicated that it should be. And the data type of size and weight should be not the same as those of color. But now they are. And how do limit you the allowed values for the colors? Color, weight and size are characteristic of your products so that they should have been modeled like this.
See how easily your questions becomes after remodeling it:
SQL> drop table product_specifications purge
2 /
Tabel is verwijderd.
SQL> drop table products purge
2 /
Tabel is verwijderd.
SQL> create table products (id,name,color,weight,height)
2 as
3 select 1, 'TV', 'Blue', 20, null from dual union all
4 select 2, 'Cellphone', 'Blue', 20, null from dual union all
5 select 3, 'Laptop', 'Blue', 25, null from dual union all
6 select 4, 'DVD Player', 'Blue', 20, 10 from dual union all
7 select 5, 'Radio', 'Blue', 20, null from dual union all
8 select 6, 'VCR', 'Blue', 20, 10 from dual
9 /
Tabel is aangemaakt.
SQL> select * from products
2 /
ID NAME COLO WEIGHT HEIGHT
---------- ---------- ---- ---------- ----------
1 TV Blue 20
2 Cellphone Blue 20
3 Laptop Blue 25
4 DVD Player Blue 20 10
5 Radio Blue 20
6 VCR Blue 20 10
6 rijen zijn geselecteerd.
SQL> select p1.name
2 , p2.name
3 from products p1
4 , products p2
5 where p1.id < p2.id
6 and ( p1.color = p2.color or (p1.color is null and p2.color is null))
7 and ( p1.weight = p2.weight or (p1.weight is null and p2.weight is null))
8 and ( p1.height = p2.height or (p1.height is null and p2.height is null))
9 /
NAME NAME
---------- ----------
TV Cellphone
TV Radio
Cellphone Radio
DVD Player VCR
4 rijen zijn geselecteerd.
I hope this helps.
Kind regards
Rob.
Tags: Database
Similar Questions
-
Help with the query to select only one record from the result set in double
Hello
Please help with the query. Version of Oracle database we use is 10g R2.
I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec
ID Org DF Sec Sub-Sec (163) CQ CPDM CPDM HD (163) PC ENG ENG ENG (163) CQ ASIC ASIC IS 8888 TS TAC TAC TAC (163) TS HE HE SW 6789 CQ INFO INFO FOS 6789 PC SECSYS SECSYS INFO1 6789 TS SECSYS SECSYS INFO2 9009 PC BMS BMS BMS1 My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.
ID DSB DF SEC Sub-Sec (163) CQ CPDM CPDM HD 8888 TS TAC TAC TAC 6789 CQ INFO INFO FOS 9009 PC BMS BMS BMS1 Thank you
Orton
Hello
This sounds like a job for ROW_NUMBER:
WITH got_r_num AS
(
SELECT id, DSB, df, s, sub_sec org
ROW_NUMBER () OVER (PARTITION BY ID.
ORDER BY org
) AS r_num
OF view_x
)
SELECT id, DSB, df, sub_sec s,
OF got_r_num
WHERE r_num = 1
;
He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data. (I know that you said that you were a view selection. Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places. (I didn't quite understand the explanation above. I don't know why you want toID ORG DF DRY SUB_SEC
-- --- -- --- -------
1234 CQ DPRK DPRK HD
and is not
1234 IS CQ ASIC, ASIC
or
TS 1234 IT IT SW
or
1234 CQ ASIC ASIC HD
)
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
need help with the query, thx
Hello
I need a little help with the query I have to write;
the table has 4 columns:
what I am asking is the following result: salary according to the latest available yearcol1 col2 col3 col4 emp_name empl_id salary year content of data: col1 col2 col3 col4 smith 12 1200 1999 smith 12 1340 2000 smith 12 1500 2001 jones 13 1550 1999 jones 13 1600 2000 aron 14 1200 2002
i.e.
ID appreciate some guidance on how to achievesmith 12 1500 2001 jones 13 1600 2000 aron 14 1200 2002
Thank you
Rgdsselect *from (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc) rn from
) where rn=1 -
small request I have given as below,
Month ProductNo CustomerNo units
9001 1001 Jan - 09 100
9002 1002 Jan - 09 200
9003 1003 Jan - 09 300
Jan 9001 400 ABCCustomer
9002 1004 Jan - 09 500
for all record - if column - customerNo starts with digital it must show as CN_ * other wise of the same name.
Result must be
9001 100 CN_1001-09 Jan
9002 200 CN_1002-09 Jan
9003 300 CN_1003-09 Jan
Jan 9001 400 ABCCustomer
9002 500 CN_1004-09 Jan
Can help get the queryA logic that is easier to implement this is as below
SQL> with t as (select 'jan' Month, 9001 ProductNo,'1001-09' CustomerNo,100 Units from dual union all 2 select 'jan', 9002, '1002-09', 200 from dual union all 3 select 'jan', 9003, '1003-09', 300 from dual union all 4 select 'jan', 9001, 'ABCCustomer', 400 from dual union all 5 select 'Jan', 9002, '1004-09', 500 from dual) 6 select month,productno,case when upper(substr(customerno,1,1))=lower(substr(customerno,1,1)) 7 then 'CN_'||customerno else customerno end customerno,units from t; MON PRODUCTNO CUSTOMERNO UNITS --- ---------- -------------- ---------- jan 9001 CN_1001-09 100 jan 9002 CN_1002-09 200 jan 9003 CN_1003-09 300 jan 9001 ABCCustomer 400 Jan 9002 CN_1004-09 500
TRY WITH THIS upper (substr(customerno,1,1)) = lower (substr(customerno,1,1))
-
Help with the query to create hourly statistics
Hello!
I have an array of jobs. Each task has a start_date and a column end_date. end_date can be null if the job is still running.
I need to create a query to display the number of jobs running for all hours during the last two weeks.
A job can run for more than an hour.
I tried to define what it means for a job during an interval:
Job.Start_date < = Interval.end AND Job.Finish_date > = Interval.start
Can help you with this query?
Thank you!
Mihai
Hi, Mihai,
User810719-Oracle wrote:
Hello!
I have an array of jobs. Each task has a start_date and a column end_date. end_date can be null if the job is still running.
I need to create a query to display the number of jobs running for all hours during the last two weeks.
A job can run for more than an hour.
I tried to define what it means for a job during an interval:
Job.Start_date <= interval.end="" and="" job.finish_date="">= Interval.start...
=>
You gave essentially the solution yourself. You just need to outside join your jobs table to a table (or, in the example below, a result set that acts like a table) containing 1 row for each interval. You can use NVL to equate finish_dates with an effective DATE NULL, so they will be counted:
WITH intervals AS
(
SELECT TRUNC (SYSDATE, 'HH') - ((LEVEL-1)/24) AS interval_start
, TRUNC (SYSDATE, 'HH') - ((LEVEL-2)/24) AS interval_end
OF the double
CONNECT BY LEVEL<= 14="" *="">=>
)
SELECT i.interval_start
EARL of (j.start_date) AS jobs_running
Intervals I have
LEFT OUTER JOIN jobs j WE j.start_date<=>=>
AND NVL (j.finish_date
i.interval_end
) > = i.interval_start
;
If you would care to post a small example of data (CREATE TABLE and INSERT statements) and the results desired from this data, I was able to test this.
Simplify the problem for display. Do what you are interested only for the past 6 hours, not the last 2 weeks. We will find a solution that can easily adapt to any number or intervals.
-
Failed to create the query? (Interesting Scenerio)
Hi all, I am unable to create a query for results with the following data below. Any help will be appreciated?
Expected results
ID1 NAME1 NAME2 ID2
1 test1 test2 2
3 4 test4 test3
5 of test5 test6 6
Thanks in advanceSelect o.id id1, o.name name1, e.id id2, e.name name2 from emp o, emp e where o.id+1=e.id(+) and mod(o.id,2)=1;
ID odd on Column1 and following the same id on Column2.
Max
-
Help with the query to return the last possible value
Can someone please help me to create a query for the situation below?
Table: TABLEA
Columns:
FACID VARCHAR2 (10),
DEPTID VARCHAR2 (10),
CHARGENUMBER NUMBER (10)
I have the following data:
A, B, 1
A, B, 2
C, D, 3
C, D, 4
I will return the following:
A, B, 2
C, D, 4
In other words, I would return the last possible CHARGENUMBER for FACID and DEPTID.
The table has no index, and it is responsible for a worksheet in that order.
Thank you very much!Hello
If you have a TIMESTAMP column, called entry_dt, you can use a Top - N query like this to find the last x entries.
WITH got_rnum AS ( SELECT my_table.* , RANK () OVER (ORDER BY entry_dt DESC) AS rnum FROM my_table ) SELECT * -- or list all columns except rnum FROM got_rnum WHERE rnum <= x ;
It is very common to have a trigger to ensure that columns like entry_dt are met.
If you have only one statement that inserts with hundreds of lines, they can all have the same entry_dt. (The value of SYSTIMESTAMP is constant throughout a statement, even if it takes a few seconds).
The above query uses RANK, so if you tell him you want the last 10 entries, it can return more than 10, because it includes all lines with exactly the same entry_dt as the 10th. If you want to exactly 10 rows returned, even if there is a tie for 10th place, then use ROW_NUMBER instead of RANK; the rest of the query is the same. -
Create the query by combining data from DBSS_Data_Model and HostModel
Hello
I am trying to create a dashboard with the host server list and instances of SQL Server running on the host.
And I am interested in creating a query by combining data model of data in SQL Server (DBSS_Data_Model) and the host (Hosts) data model, say: which connects DBSS_SQL_Server_Host and host.
I wonder if there is way to do it?
Thank you
Mark
Something like this function should work:
def physicalHost = nullqueryStatement = server.QueryService.createStatement("(Host where name = '$hostName')")result = server.QueryService.executeStatement(queryStatement)objs=result.getTopologyObjects() if (objs != null && objs.size() > 0) { physicalHost = objs.get(0)}return physicalHost
When the input parameter "hostName" is DBSS_SQL_Server_Host.physical_host_name
Kind regards
Brian Wheeldon
-
Hi, can someone help me with the query. I try to display comm based on calculation below
SAL < 5000 then 10%
5000 - 10000 then 15%
> 10000 then 20%
This is the query
DECLARE
v_comm number (7.2);
v_Name emp.ename%type;
v_empno emp.empno%type;
v_sal emp.sal%type;
BEGIN
SELECT ename, empno, sal IN
v_Name, v_empno, v_sal
EMP;
v_comm: = (IF v_sal < v_sal*.10 then 5000;)
ELSIF v_sal between 5001 AND 10000 THEN v_sal*.15;
Of ANOTHER v_sal > 10001 THEN v_sal*.20;
END IF ;);
dbms_output.put_line(v_Name||) e with empno' | v_empno | "win a comm' | v_comm);
END; /
also tried
DECLARE
v_comm number (7.2);
v_Name emp.ename%type;
v_empno emp.empno%type;
v_sal emp.sal%type;
BEGIN
SELECT ename, empno, sal IN
v_Name, v_empno, v_sal
EMP;
IF v_sal < v_comm then 5000: = v_sal*.10;
ELSIF v_sal between 5001 AND 10000 THEN v_comm: = v_sal*.15;
Of ANOTHER v_sal > 10001 THEN v_comm: = v_sal*.20;
END IF ;);
dbms_output.put_line(v_Name||) e with empno' | v_empno | "win a comm' | v_comm);
END;
/
Hello
Look at the syntax of the IF in the PL/SQL manual. Comapre to the instruction BOX and also the expression BOX.
Perhaps, instead of an IF statement
v_comm: = (IF v_sal<5000 then="">5000>
ELSIF v_sal between 5001 AND 10000 THEN v_sal*.15;
ELSE v_sal > 10001 THEN v_sal*.20;
END IF ;);
you wanted to write an expression BOX, like this:
v_comm: = BOX
WHEN v_sal< 5000 ="" then="" v_sal="" *="">
WHEN v_sal BETWEEN 5001 AND 10000 THEN v_sal *.15
WHEN v_sal > 10001 THEN v_sal *.20
END;
Or perhaps cela:
v_comm: = v_sal * CASE
WHEN v_sal<= 5000="" then="">= >
WHEN v_sal<= 10000="" then="">=>
OF AUTRE.20
END;
You can also use a CASE expression in the SELECT statement.
-
Need help with the query. Help, please
Hey everyone, need your help. Thank you in advance. In my view, there is function Pivot. Just do not know how to use this function. I have the query that works. The result is:
11-111-1111 Vlad 16505 01/04/2013 5 August 13 dental plan pre-tax amount 29,65
11-111-1111 Vlad 16505 01/04/2013 dental pre-tax 5 August 13 Plan level EE + SP
11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Option TOP dental plan
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax dental care plan pay the value
11-111-1111 16505 Vlad 01/04/2013 dental pre-tax 5 August 13 Plan period Type
11-111-1111 Vlad 16505 01/04/2013 amount pre-tax medical Plan of 5 August 13 149
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Medical Plan level EE + SP
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan medical Option MED
11-111-1111 Vlad 16505 01/04/2013 5 August 13 plan pre-tax pay value
11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Medical Plan period Type
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan PPO medical Plan
11-111-1111 Vlad 16505 01/04/2013 5 August 13 Vision Plan amount 5.94 pre-tax
But I need the result to be
Amount of SSN ID name item level Option PayValue period Type
11-111-1111 Vlad 16505 01/04/2013 null null high of 5 August 13 pre-tax Dental Plan 29,65 EE + SP
11-111-1111 Vlad 16505 01/04/2013 null null MED 5 August 13 149 medical plan pre-tax EE + SP
11-111-1111 Vlad 16505 01/04/2013 Vision Plan before taxes of 5 August 13
Select distinct
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as EMPLOYEE_FULL_NAME,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as Date_Of_Hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_valueOf
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1'
order of petf.element_name;Change with your query
SELECT * FROM (select distinct)
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as employee_full_name,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_value
Of
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1')
PIVOT (MAX (screen_entry_value) FOR (name) TO ("Amount" AS 'Amount', 'level' AS 'level', 'Option High' AS 'High Option', 'Pay the value' AS 'Value to pay', 'Period of Type' AS 'Type period'))
order by element_name;
(GOLD)
SELECT ssn,
Employee_number,
employee_full_name,
date_of_hire,
effective_start_date,
element_name,
Max (decode (Name, 'Amount', screen_entry_value)) 'amount. "
Max (decode (Name, 'Level', screen_entry_value)) 'level ',.
MAX (DECODE (name, "High Option", screen_entry_value)) "High Option",
MAX (DECODE (name, 'Value of pay', screen_entry_value)) 'value of pay. "
MAX (DECODE (name, 'Period Type', screen_entry_value)) 'period of Type '.
FROM (select distinct)
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as employee_full_name,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_value
Of
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1')
GROUP BY ssn, employee_number, employee_full_name, date_of_hire, effective_start_date, NOM_ELEMENT
order by element_name;
-
Failed to create the query.
Hello
I'm new to jpa. When I create the "g game SELECTION g WHERE g.player1_id =: use ' I get the following" unknown state or association field of error [player1_id] class [entity.» Game]. "
Here is the generated netbean feature classes.
package entity;
import java.io.Serializable;
to import java.util.Collection;
import java.util.Date;
Javax.persistence import. *;
Import javax.validation.constraints.NotNull;
Import javax.validation.constraints.Size;
Import javax.xml.bind.annotation.XmlRootElement;
Import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author ara Yeritsian
*/
@Entity
@Table (name = 'game')
@XmlRootElement
@NamedQueries({)
@NamedQuery (name = "Game.findAll", query = "SELECT game g g"),
@NamedQuery (name = "Game.findById", query = "SELECT game g g WHERE g.id =: id").
@NamedQuery (name = "Game.findByState", query = "SELECT game g g WHERE g.state =: State").
@NamedQuery (name = "Game.findByStartRulles", query = "SELECT game g g WHERE g.startRulles =: startRulles");
@NamedQuery (name = "Game.findByStartDate", query = "SELECT game g g WHERE g.startDate =: startDate").
({@NamedQuery (name = "Game.findByClock", query = "SELECT game g g WHERE g.clock =: clock")})
/ public class game implements Serializable {}
private static final long serialVersionUID = 1 L;
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column (name = "id")
whole ID private;
@Basic(optional = false)
@NotNull
@Size (min = 1, max = 16)
@Column (name = "State")
private state String;
@Basic(optional = false)
@NotNull
@Column (name = "start_rulles")
private short startRulles;
@Column (name = "start_date")
@Temporal (TemporalType.TIMESTAMP)
private Date startDate;
@Column (name = "clock")
clock of integers private;
@OneToMany (waterfall = CascadeType.ALL, mappedBy = "gameId")
Private Collection < MoveHistory > moveHistoryCollection;
@JoinColumn (name = "player2_id", referencedColumnName = "id")
@ManyToOne
player2Id private user;
@JoinColumn (name = "player1_id", referencedColumnName = "id")
@ManyToOne(optional = false)
player1Id private user;
public Game() {}
}
{public game (Integer id)
This.ID = id;
}
{public game (id Integer, String State, short startRulles)
This.ID = id;
This.State = State;
this.startRulles = startRulles;
}
public Integer getId() {}
return the id;
}
{} public void setId (Integer id)
This.ID = id;
}
public String getState() {}
return status;
}
{} public void setState (State of the chain)
This.State = State;
}
{public getStartRulles() short
Return startRulles;
}
{} public void setStartRulles (abbreviated startRulles)
this.startRulles = startRulles;
}
public Date getStartDate() {}
return startDate;
}
{} public void setStartDate (Date startDate)
this.startDate = startDate;
}
public Integer getClock() {}
return the clock;
}
{} public void setClock (whole clock)
This.Clock = clock;
}
@XmlTransient
public Collection < MoveHistory > getMoveHistoryCollection() {}
Return moveHistoryCollection;
}
{} public void setMoveHistoryCollection (Collection < MoveHistory > moveHistoryCollection)
this.moveHistoryCollection = moveHistoryCollection;
}
public getPlayer2Id() {} user
Return player2Id;
}
public void setPlayer2Id (User player2Id) {}
This.player2Id = player2Id;
}
public getPlayer1Id() {} user
Return player1Id;
}
public void setPlayer1Id (User player1Id) {}
This.player1Id = player1Id;
}
@Override
public int hashCode() {}
int hash = 0;
hash += (id! = null? id.hashCode (): 0);
Returns the hash;
}
@Override
public boolean equals (Object, object) {}
TODO: WARNING - This method will not work in the case of identification fields are not defined
If (!) object instanceof game))) {}
Returns false;
}
Game another object = (game);
If ((this.id == null & & other.id! = null) |) ((this.id! = null & &! this.id.equals (other.id))) {
Returns false;
}
Returns true;
}
@Override
public String toString() {}
return "entity. Game [id ="+ id +" "] ';
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package entity;
import java.io.Serializable;
to import java.util.Collection;
Javax.persistence import. *;
Import javax.validation.constraints.NotNull;
Import javax.validation.constraints.Size;
Import javax.xml.bind.annotation.XmlRootElement;
Import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author ara Yeritsian
*/
@Entity
@Table (name = "user")
@XmlRootElement
@NamedQueries({)
@NamedQuery (name = "User.findAll", query = "SELECT u OF u user"),
@NamedQuery (name = "User.findById", query = "SELECT u FROM user u WHERE u.id =: id").
@NamedQuery (name = "User.findByEmail", query = "SELECT u OF u WHERE u.email = user: e-mail").
@NamedQuery (name = "User.findByPassword", query = "SELECT u OF u WHERE u.password = user: password").
@NamedQuery (name = "User.findByRating", query = "SELECT u OF u WHERE u.rating = user: side").
@NamedQuery (name = "User.findByNickname", query = "SELECT u OF u WHERE u.nickname = user: username").
({@NamedQuery (name = "User.findBySecurityQuestionAnswer", query = "SELECT u OF u WHERE u.securityQuestionAnswer = user: securityQuestionAnswer")})
User/public class implements Serializable {}
private static final long serialVersionUID = 1 L;
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column (name = "id")
whole ID private;
@Pattern (regexp = "[a-z0-9! #$% &'* + / = ? ^ _'{|} ~-]+(?:\ \. (([a-z0-9! #$% &'* + / =? ^ _'{|} ~-] +) * @(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.) + [a-z0-9](?:[a-z0-9-]*[a-z0-9])? ", message =" invalid email address") //if the field contains E-mail address use this annotation to apply field validation"
@Basic(optional = false)
@NotNull
@Size (min = 1, max = 45)
@Column (name = "email")
private String email;
@Basic(optional = false)
@NotNull
@Size (min = 1, max = 45)
@Column (name = "password")
private String password;
@Basic(optional = false)
@NotNull
@Column (name = "rating")
private int rating;
@Basic(optional = false)
@NotNull
@Size (min = 1, max = 45)
@Column (name = "nickname")
private; channel nickname
@Basic(optional = false)
@NotNull
@Size (min = 1, max = 45)
@Column (name = "security_question_answer")
private String securityQuestionAnswer;
@OneToMany (waterfall = CascadeType.ALL, mappedBy = "playerId")
Private Collection < MoveHistory > moveHistoryCollection;
@OneToMany (mappedBy = "player2Id")
Private Collection < Game > gameCollection;
@OneToMany (waterfall = CascadeType.ALL, mappedBy = "player1Id")
Private Collection < Game > gameCollection1;
@JoinColumn (name = "security_question_id", referencedColumnName = "id")
@ManyToOne(optional = false)
Private SecurityQuestion securityQuestionId;
{public User()
}
public user (id Integer) {}
This.ID = id;
}
public user (id Integer, String email, String password, int side, String username, String securityQuestionAnswer) {}
This.ID = id;
This.email = email;
This.password = password;
This.Rating = notes;
This.Nickname = username;
this.securityQuestionAnswer = securityQuestionAnswer;
}
public Integer getId() {}
return the id;
}
{} public void setId (Integer id)
This.ID = id;
}
public String getEmail() {}
return of electronic mail;
}
{} public void setEmail (String email)
This.email = email;
}
public String getPassword() {}
return the password;
}
public void setPassword (String password) {}
This.password = password;
}
public int getRating() {}
return of qualification;
}
public void setRating (int side) {}
This.Rating = notes;
}
public String getNickname() {}
return the nickname;
}
{} public void setNickname (string name)
This.Nickname = username;
}
public String getSecurityQuestionAnswer() {}
Return securityQuestionAnswer;
}
{} public void setSecurityQuestionAnswer (String securityQuestionAnswer)
this.securityQuestionAnswer = securityQuestionAnswer;
}
@XmlTransient
public Collection < MoveHistory > getMoveHistoryCollection() {}
Return moveHistoryCollection;
}
{} public void setMoveHistoryCollection (Collection < MoveHistory > moveHistoryCollection)
this.moveHistoryCollection = moveHistoryCollection;
}
@XmlTransient
public Collection < Game > getGameCollection() {}
Return gameCollection;
}
{} public void setGameCollection (Collection < Game > gameCollection)
this.gameCollection = gameCollection;
}
@XmlTransient
public Collection < Game > getGameCollection1() {}
Return gameCollection1;
}
public void setGameCollection1 (Collection < Game > gameCollection1) {}
this.gameCollection1 = gameCollection1;
}
public SecurityQuestion getSecurityQuestionId() {}
Return securityQuestionId;
}
{} public void setSecurityQuestionId (SecurityQuestion securityQuestionId)
this.securityQuestionId = securityQuestionId;
}
@Override
public int hashCode() {}
int hash = 0;
hash += (id! = null? id.hashCode (): 0);
Returns the hash;
}
@Override
public boolean equals (Object, object) {}
TODO: WARNING - This method will not work in the case of identification fields are not defined
If (!) object instanceof user))) {}
Returns false;
}
The user = (user) another object;
If ((this.id == null & & other.id! = null) |) ((this.id! = null & &! this.id.equals (other.id))) {
Returns false;
}
Returns true;
}
@Override
public String toString() {}
return "entity. The user [id ="+ id +" "] ';
}
}
Published by: 927714 on April 15, 2012 01:04JPQL use attributes and properties of entity in queries, not the SQL field names, you cannot use "player1_id" because it does not exist in the game entity. I don't know what you pass in the: the user parameter, but if it is a principal user Id, you should try using ' g.player1Id.id =: user. If you pass in the user entity, you can use "g.player1Id =: user" instead.
Best regards
Chris -
Please help improve the query with the analytic function
The mentioned below query takes about 10 hours to complete (10.2.0.4).
There are 3 tables (table t has a relationship 1: n with table e and k table also has a relationship 1: n with table e).
Table a contains 200,000 lines. (this table is truncated and inserted several times a week)
E table contains rows of 1Mio.
K table contains rows of 170Mio.
I need a query that takes the latest 3 posts for a given t_id:drop table t; create table t ( t_id number, constraint t_pk primary key (t_id) ); drop table e; create table e ( e_id number, e_doc nvarchar2(16), e_date date, constraint e_pk primary key (e_id) ); drop table k; create table k ( t_id number, e_id number ); create unique index k_i1 on k(t_id, e_id); exec dbms_stats.gather_table_stats(user, 'T'); exec dbms_stats.gather_table_stats(user, 'K'); exec dbms_stats.gather_table_stats(user, 'E'); -- Sample data: insert into t(t_id) values (100); insert into t(t_id) values (101); insert into t(t_id) values (102); insert into t(t_id) values (103); insert into e(e_id, e_doc, e_date) values (200, 'doc 200', to_date('01.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (201, 'doc 201', to_date('02.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (202, 'doc 202', to_date('03.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (203, 'doc 203', to_date('04.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (204, 'doc 204', to_date('05.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (205, 'doc 205', to_date('06.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (206, 'doc 206', to_date('07.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (207, 'doc 207', to_date('08.01.2010', 'DD.MM.YYYY')); insert into k(t_id, e_id) values (100, 200); insert into k(t_id, e_id) values (100, 201); insert into k(t_id, e_id) values (100, 202); insert into k(t_id, e_id) values (100, 203); insert into k(t_id, e_id) values (101, 203); insert into k(t_id, e_id) values (101, 204); select k.t_id, e.e_date, e.e_id, e.e_doc from e, k, t where k.e_id = e.e_id and k.t_id = t.t_id order by k.t_id, e.e_date desc; T_ID E_DATE E_ID E_DOC ---------- -------- ---------- ---------------- 100 04.01.10 203 doc 203 100 03.01.10 202 doc 202 100 02.01.10 201 doc 201 100 01.01.10 200 doc 200 101 05.01.10 204 doc 204 101 04.01.10 203 doc 203
The example query takes several hours in production.T_ID E_DOC_LIST ---------- ----------------------- 100 doc 200/doc 201/doc 202 101 doc 203/doc 204 Sample query: select t_id, e_doc_list from ( select k.t_id, row_number() over(partition by k.t_id order by k.t_id, e.e_date desc) r_num, rtrim( lag(e.e_doc, 0) over(partition by k.t_id order by k.t_id, e.e_date) || '/' || lag(e.e_doc, 1) over(partition by k.t_id order by k.t_id, e.e_date) || '/' || lag(e.e_doc, 2) over(partition by k.t_id order by k.t_id, e.e_date), '/') e_doc_list from e, k, t where k.e_id = e.e_id and k.t_id = t.t_id order by k.t_id, e.e_date desc ) where r_num = 1 ; T_ID E_DOC_LIST ---------- -------------------------------------------------- 100 doc 203/doc 202/doc 201 101 doc 204/doc 203
The r_num = 1 filter is applied quite late. Is there another way to generate the query or even review the tables.
For the sample query: ----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 468 | 6 (50)| 00:00:01 | |* 1 | VIEW | | 6 | 468 | 6 (50)| 00:00:01 | |* 2 | WINDOW SORT PUSHED RANK | | 6 | 216 | 6 (50)| 00:00:01 | | 3 | WINDOW SORT | | 6 | 216 | 6 (50)| 00:00:01 | | 4 | NESTED LOOPS | | 6 | 216 | 4 (25)| 00:00:01 | | 5 | MERGE JOIN | | 6 | 198 | 4 (25)| 00:00:01 | | 6 | TABLE ACCESS BY INDEX ROWID| E | 8 | 208 | 2 (0)| 00:00:01 | | 7 | INDEX FULL SCAN | E_PK | 8 | | 1 (0)| 00:00:01 | |* 8 | SORT JOIN | | 6 | 42 | 2 (50)| 00:00:01 | | 9 | INDEX FULL SCAN | K_I1 | 6 | 42 | 1 (0)| 00:00:01 | |* 10 | INDEX UNIQUE SCAN | T_PK | 1 | 3 | 0 (0)| 00:00:01 | ----------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("R_NUM"=1) 2 - filter(ROW_NUMBER() OVER ( PARTITION BY "K"."T_ID" ORDER BY "K"."T_ID",INTERNAL_FUNCTION("E"."E_DATE") DESC )<=1) 8 - access("K"."E_ID"="E"."E_ID") filter("K"."E_ID"="E"."E_ID") 10 - access("K"."T_ID"="T"."T_ID") and for query in production --------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| --------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3118K| 425M| | 160K (1)| | 1 | VIEW | | 3118K| 425M| | 160K (1)| | 2 | SORT ORDER BY | | 3118K| 163M| 383M| 160K (1)| | 3 | WINDOW SORT PUSHED RANK| | 3118K| 163M| 383M| 160K (1)| | 4 | WINDOW SORT | | 3118K| 163M| 383M| 160K (1)| | 5 | HASH JOIN | | 3118K| 163M| 40M| 33991 (1)| | 6 | TABLE ACCESS FULL | E | 1053K| 28M| | 4244 (1)| | 7 | NESTED LOOPS | | 3118K| 80M| | 21918 (1)| | 8 | TABLE ACCESS FULL | T | 144K| 1829K| | 282 (2)| | 9 | INDEX RANGE SCAN | K_I1 | 22 | 308 | | 1 (0)| ---------------------------------------------------------------------------------------
TimWong765 wrote:
...
Table a contains 200,000 lines. (* this table is truncated and inserted several times a week *)You could be in one of the rare cases where the index should be rebuild, take a look in the following thread:
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:6601312252730 #69571308712887 (search for 'index of Sweeper')
Make sure that you have checked if you are in this case before going for an expensive index rebuild.Nicolas.
-
Need help with the query string manipulation
Hello
With the help of 10.1.0.4.2
Given a table called PREFIX_CODES that contains a column called PREFIX_CODE
with the following data:
PREFIX_CODE - VARCHAR2 (20)
-------------------
AAA
BENAMER
CARTER
and another table called SUBSCRIBERS with a column called SUBSCRIBER_ID
with the following data:
SUBSCRIBER_ID - VARCHAR2 (30)
---------------------
BBBB-123456
AAA-444444
DD-2222222
EEEE-888888
Is there a query that will pull all the SUBSCRIBER_ID that begin with
each of the PREFIX_CODES? The following query is not valid, but it
This will give you an idea of what I'm trying to do:
SELECT SUBSCRIBER_ID
SUBSCRIBERS
WHERE AS SUBSCRIBER_ID (SELECT PREFIX_CODE |) » %'
OF PREFIX_CODES)
Using the data from above, I would like that the query to return:
BBBB-123456
AAA-444444
Thanks for your help!Hello
Welcome to the forum!
You were on the right track. To find if a given subscriber corresponds to any prefix_code, you can do an EXISTS subquery:
SELECT subscriber_id FROM subsribers s WHERE EXISTS ( SELECT NULL FROM prefix_codes WHERE s.subscriber_id LIKE prefix_code || '%' ) ;
This will tell you if at least a prefix code. It won't tell you exactly how many, or what they were.
Your message, I'm guessing that there may be more than one, and you can deduct the subscriber_id itself, then the above query should work for you. -
I put it in my table:
SQ_NO CUST_ID YEAR1 YEAR2 10 10028354 1996 2002 SELECT 10 SQ_NO, 10028354 CUST_ID, 1996 BY AN1 AN2 2002
FROM DUAL;
On a line I need to generate the number of lines between an1 and an2 and I need to generate only even numbers in the column of the year2. The result should be like this:
10 10028354 1996 1996
10 10028354 1996 1998
10 10028354 1996 2000
10 10028354 1996 2002
I tried a lot of things, but nothing has worked for me. I'd appreciate the support.
Kind regards
skas
Hello
skas wrote:
My bad I find it hard to understand this function correctly at the moment.
There is no function affected by the query you posted.
May be I pressure to quickly generate this report this is why I am not able to focus on learning patiently rather more interested in the realization of the goal.
When you're ready to learn how works the CONNECT BY clause, see
http://www.adp-GmbH.ch/ora/SQL/connect_by.html and/or
http://www.oradev.com/connect_by.jsp
I used Oracle for years before I learned how to CONNECT BY works. I'm glad that I finally took the time to learn; It is very useful.
I added a line in addition in the request, but now I'm getting duplicates. I tried to use the group by clause, but both options still holding separate, when I run the query against the current table that has rows of 50 K.
If the table has more than 1 line, then you need a condition in addition to LEVEL<= x ="" in="" the="" connect="" by="" clause;="" some="" condition(s)="" using="" the="" prior="">=>
Depending on your version of Oracle, he gets the results you posted:
SELECT sq_no
cust_id
, by an1
by an1 + ((LEVEL - 1)
* 2
) AS yearx
A
CONNECT BY LEVEL<= (="" (year2="" -="">=>
/ 2
) + 1
AND sq_no = PRIOR sq_no
AND PRIOR SYS_GUID () IS NOT NULL
ORDER BY 2, 3, 4
;
This assumes that a.sq_no is unique.
Beware of any solution that requires SELECT DISTINCT. Very often, it's just a very expensive way to deal with a problem rather than solve it.
-
Need help with the query to get the County
Hello
Oracle 10 g 2 10.2.0.3 - 64 bit
I want back the number of accounts with two different types of funds (say A and B). Some accounts hold only one of the two funds, and some support both. I want to get the counts like this:
- account held funds - has only
- accounts holding funds-B only
- accounts holding the Fund-A and B funds
Here is what I started with but need assistance to meet the requirement above:
select count(distinct acct.bkoff_acct_no ) accounts_holding_fund_A from xe_account acct, xec_tal_investment_mandate iman, xec_tal_asset_allocation alloc, xe_benchmark bmark, xe_benchmark_usage bu, xe_object_description xod, xec_asset_class cls where iman.mandate_status_cd='A' and cls.asset_class_cd = alloc.asset_class_cd and iman.mandate_id = alloc.mandate_id and acct.account_id = iman.object_id and iman.object_type_cd = 'ACCT' and iman.mandate_id = xod.object_id and xod.field_nm='XEC_TAL_INVESTMENT_MANDATE.COMMENT_TXT' and xod.language_cd = 'E' and acct.acct_status_cd = 'O' and bu.object_type_cd(+) = 'TMAA' and bu.object_id(+) = alloc.asset_allocation_id and bmark.benchmark_id(+) = bu.benchmark_id and alloc.resp_txt like '%fund-A%'
And suppose that the Fund-B has resp_txt like ' % of Fund-B»
Please suggest.
Concerning
Hello
Here is another way, it is easier to adapt to different jobs and different numbers of jobs:
WITH got_distinct_jobs AS
(
SELECT DISTINCT deptno, job
FROM scott.emp
WHERE job IN ("ANALYST", "CLERKS") - or what
)
got_job_list AS
(
SELECT LISTAGG (job, ",") THE Group (ORDER BY work) AS job_list
OF got_distinct_jobs
GROUP BY deptno
)
SELECT job_list
COUNT (*) AS num_departments
OF got_job_list
GROUP BY job_list
;
This shows all the combinations of the jobs listed in the WHERE clause of got_distinct_jobs. You don't need to change anything else in the query. There may be any number of jobs.
Output:
JOB_LIST NUM_DEPARTMENTS
------------------------------ ---------------
CLERK 2
ANALYST, CLERK 1
Maybe you are looking for
-
Hello Recently switched to FIOS digital voice service. I have a HP Officejet Pro 8500 A909g. Y at - it a patch or other difficulty that I can use to send a fax? Receives errors in communication since going digital. Thank you Michael
-
HP 15 r110dx: password Administration start
My laptop was stolen and recovered recently. He asked a start/admin password that I do not have. After three doesn't have a password it crashes and gives me the code. 86573057 help please?
-
No update Windows after installing SP1
I have several machines I restore for friends, but I'm having a problem with the updates of windows 7. I can receive and install updates all the way up to and including SP1, but once SP1 is installed, no updates more don't get down. I left the verifi
-
BlackBerry Smartphones Google Contacts Sync Curve 8310 problem
Hi all I managed to solve the problems that I had with the calendar synchronization, then learned recently I had no newer OS BB (4.5 as I write this) or the most recent Google (0.5.13) sync software. My carrier is ATT/Cingular in the U.S. So I update
-
Limit the bandwidth in the tunnel VPN on Cisco ASA
Hello I have a site VPN tunnel to create with the local desktop client. I fear that the traffic in the tunnel in impacting the Internet bandwidth for the entire office. Is it possible to limit bandwidth on the speed VPN tunnel. I have attached a conf