How To Write This Complex Query

hi all
i have following tables
1. employees
2. departments
3. vaccination_type
4. vaccination_subtype
5. vaccination_given
a vaccination suppose 'FLU' is to be given to an employee or an department(all employees of this department)
EXAMPLE:
vaccination type is "FLU", vaccination subtypes are "FLU1" and "FLU2"
vaccination type is "CHIC", vaccination subtypes are "CHIC1" and "CHIC2"
employee # 4444 dept# 40 assigned "FLU"
dept 50 assigned "CHIC"
employee 4444 has given only one dose means "FLU1" >>> it means defaulters
employee 5555 of dept 50 have given all 2 doses >>>>>> it means 9 emps are defaulters (total emps are 10 in dept 50)
i need to write a query to identify those employees who are defaulters
means not a single vaccination given or 1 of 3, or 2 of 3 etc
query should return 9 employees of dept 50 and employee 4444
hope you understand my problem.
Regards,

How about this one :
select empno,a.vactype,count(vacstype) From vaccination_given a
group by empno,a.vactype
having count(vacstype) < (select count(*) from vaccination_subtype where vactype = a.vactype)
EMPNO     VACTYPE     COUNT(VACSTYPE)
5553     CHIC     1
5554     CHIC     1
5560     CHIC     1
5551     CHIC     1
5559     CHIC     1
5558     CHIC     1
4444     FLU     1
5552     CHIC     1
5556     CHIC     1
5557     CHIC     1

Similar Messages

  • How to write this sql query in php code ?

    for example:
    insert into temp
    select *
    from testtable;
    after this, i will query data from sql below:
    select *
    from temp;
    how to write this php code ?
    who can help me ?
    thanks!

    Have a look at the manual to find out how to issue queries.
    http://us3.php.net/oci8

  • How to write this SQL query

    We have a table, the structure as below: (I put a blank row in the middle to make it clear)
    Product_ID     Retailer     Retail_Price
    1001          A          1.2
    1001          B          1.5
    1001          C          1.4
    1002          B          2.0
    1002          C          2.1
    1002          E          1.8
    1002          F          2.0
    1003          A          1.7
    1003          C          1.5
    Basically we use the table to compare the retail price for different retailers in terms of different products. My customer asked me to give a report based on above table but only shows the retail prices which contain retailer A.
    For example, on above table I need to give a report like below:
    Product_ID     Retailer     Retail_Price
    1001          A          1.2
    1001          B          1.5
    1001          C          1.4
    1003          A          1.7
    1003          C          1.5
    Can anybody give some ideas on how I should write a SQL to achieve this.
    Many thanks!

    SQL> create table product(
    2 Product_ID varchar2(10),
    3 Retailer varchar2(10),
    4 Retail_Price number(7,2)
    5 )
    6 /
    Table created.
    SQL> insert into product values('1001','A',1.2)
    2 /
    1 row created.
    SQL> insert into product values('1001','B',1.5)
    2 /
    1 row created.
    SQL> insert into product values('1001','C',1.4)
    2 /
    1 row created.
    SQL> insert into product values('1002','B',2.0)
    2 /
    1 row created.
    SQL> insert into product values('1002','C',2.1)
    2 /
    1 row created.
    SQL> insert into product values('1002','E',1.8)
    2 /
    1 row created.
    SQL> insert into product values('1002','F',2.0)
    2 /
    1 row created.
    SQL> insert into product values('1003','A',1.7)
    2 /
    1 row created.
    SQL> insert into product values('1003','C',1.5)
    2 /
    1 row created.
    SQL> select * from product
    2 /
    PRODUCT_ID RETAILER RETAIL_PRICE
    1001 A 1.2
    1001 B 1.5
    1001 C 1.4
    1002 B 2
    1002 C 2.1
    1002 E 1.8
    1002 F 2
    1003 A 1.7
    1003 C 1.5
    9 rows selected.
    SQL> select * from product where PRODUCT_ID in (
    2 select distinct PRODUCT_ID from product where RETAILER='A')
    3 /
    PRODUCT_ID RETAILER RETAIL_PRICE
    1001 A 1.2
    1001 B 1.5
    1001 C 1.4
    1003 A 1.7
    1003 C 1.5

  • How to write this sql  query to oracle

    Hi sir,
    i am using one query in my sql stored procedure that is:
    select @maxtime=CONVERT(Time,Out_Time+DATEADD(n,60,0)) from shift where Shift_Code = @ShiftCode
    so here i am getting this value 01/01/1900 12:00 AM
    the same i used in oracle my query is :
    to_char(Out_Time,'1900-01-01' + 0/(24*60),'DD/MM/YYYY HH:MI AM')
    INTO v_maxtime
    FROM shift
    WHERE Shift_Code = v_ShiftCode;
    but getting error that is: Encountered the symbol INTO when expecting one of the following :=(%;
    am i doing any thing wrong.
    thanks

    APC wrote:
    The error you're getting is a syntax error. In this case because you've mangled the TO_CHAR syntax. Alas I cannot give you the correct version because I cannot unpick what you're trying to do with that statement.
    It would be easier if you expalined what business logic you're trying to implement instead of asking us to interpret a piece of shonky SQL.It's yet another of the OP's questions about how to do DATEs in Oracle (so many threads it can get very confusing - even though the OP has been asked to stick to one thread!).
    The code looks like it's based on the answer I gave here:
    How to get exact query of sql in oracle?
    but clearly he doesn't understand the basic syntax of Oracle or the datatypes he's using. Sometimes you just have to give up... (I know I have)

  • How to write this query to filter combination of few values

    Hi,
    I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child.
    columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines.
    HEXA is a vaccine_id which is composite vaccine of DPT1,POL1,HBV1 & HIB1 (vaccine ids).
    I want to write to query if any of DPT1,POL1,HBV1 & HIB1 given then HEXA should not be displayed in the result.
    OR
    if HEXA is given then of course any of DPT1,POL1,HBV1 & HIB1 should not be displayed in the result.
    How to write this query?
    Regards

    Hi,
    I'm still not sure what the output you want from that sample data is. Do you just want the child_ids, like this
    CHILD_ID
           3
           4? If so, here's one way to get them:
    WITH     all_vacc_ids     AS
         SELECT     c.child_id
         ,     c.vacc_id          AS child_vacc_id
         ,     v.vacc_id
         ,     COUNT ( CASE
                             WHEN  c.vacc_id = 'HEXA'
                       THEN  1
                         END
                    )       OVER ( PARTITION BY  c.child_id
                                       )    AS hexa_itself
         FROM          vacc   v
         LEFT OUTER JOIN     chimm  c     PARTITION BY (c.child_id)
                          ON     c.vacc_id     = v.vacc_id
         WHERE   v.vacc_desc       = 'HEXA'     -- See note below
    SELECT       child_id
    FROM       all_vacc_ids
    WHERE       child_vacc_id     IS NULL
      AND       vacc_id     != 'HEXA'
      AND       hexa_itself     = 0
    GROUP BY  child_id
    rha2 wrote:there are alot of vaccines, i just put 3 for example. this query gives error: invalid relational operatorAre you saying that the vacc table contains other rows, but those other rows are not needed for this problem? It would be good if you included an example in the sample data. The query above considers only the rows in vacc where vacc_desc='HEXA'. You can have other rows in the vacc table, but they won't affect the output of this query. The query above makes no assumptions about the number of rows that have vacc_desc='HEXA'; it will report all child_ids who are missing any of them, regardless of the number (assuming the child does not have the 'HEXA' vacc_id itself, like child_id=1).
    You still haven't said which version of Oracle you're using. The query above will work in Oracle 10 (and higher).

  • How to write this query ?

    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno

    Hi,
    806540 wrote:
    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?ROW_NUMBER is just plain SQL, and has been since Oracle 8.1.
    ROW_NUMBER (or its close relative, RANK) is the simplest and most efficient way to solve this problem. Why not do this the right way?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno
    If there happens to be a tie (that is, two or more departments have the same average sal, and it is the highest), then the query above will only arbitrarily treat one of them (no telling which one) as the highest. Change ROW_NUMBER to RANK to get all departments with a claim to having the highest average sal.
    You could use the ROWNUM pseudo-column instead of ROW_NUMBER, if all you want to do is avoid ROW_NUMBER.
    Without using ROW_NUMBER or RANK, there are lots of ways involving other analytic functions, such as AVG and MAX.
    If you really, really don't want to use analytic functions at all, you can do this:
    SELECT     *
    FROM     scott.emp
    WHERE     deptno     IN  (
                      SELECT       deptno
                      FROM       scott.emp
                      GROUP BY  deptno
                      HAVING       AVG (sal) =  (
                                                       SELECT    MAX (AVG (sal))
                                               FROM          scott.emp
                                               GROUP BY  deptno
    ;

  • How can I make this complex query?

    I don’t know how can I do this complex query...
    I have the tables Customers, Vehicles and Models. A customer can have 0-N Vehicles and a vehicle have 1 Model.
    Customers: ID_Customer (PK), Name, LastName...
    Vehicles: ID_Vehicle (PK), ID_Customer, ID_Model, date_sale
    Models: ID_Modelo (PK), Model_Name
    Then I need to know the buy average time (date_sale) between 2 models (ID_Model)
    For example I have these Vehicles:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    1................................123....................1.............21/05/2000
    2................................459....................3............ 16/08/2000
    3................................123....................2............ 28/06/2001
    4................................516....................1............ 09/09/2001
    5................................459....................4............ 18/10/2002
    6................................516....................2............ 20/12/2002
    If I want to know the buy average time (date_sale) between ID_Model 1 and ID_Model 2 it is. (403 + 467) / 2 = 435 days !!!
    * Customer 123 (model 1 to 2): 25/06/2001 – 21/05/2000 ==> 403 days
    * Customer 516 (model 1 to 2): 01/12/2002 – 01/05/2000 ==> 467 days.
    I need to do the query for all the combination models. For example If I have the Models 1, 2 and 3 I need to obtain:
    Source_Model.....Target_Model....Buy_Average_Time
    1......................................1....................... xxx days
    1......................................2....................... xxx days
    1......................................3....................... xxx days
    2......................................1....................... xxx days
    2......................................2....................... xxx days
    2......................................3....................... xxx days
    3......................................1....................... xxx days
    3......................................2....................... xxx days
    3......................................3....................... xxx days
    If it is necessary I could create a table with the fields Source_Model, Target_Model and Buy_Average_Time for accelerate the query time response.
    But how can I do this query??????????
    Thanks very much!!!

    Hi,
    Thanks for your reply but It is not correct for me because the Customer could have several vehicles in her life.
    If I make the query with my examples data it is OK
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    1................................123....................1.............21/05/2000
    2................................459....................3............ 16/08/2000
    3................................123....................2............ 28/06/2001
    4................................516....................1............ 09/09/2001
    5................................459....................4............ 18/10/2002
    6................................516....................2............ 20/12/2002
    select v1.id_model as source_model,
    v2.id_model as target_model,
    avg (v2.date_sale - v1.date_sale) || ' days' as buy_average_time
    from vehicles v1,
    vehicles v2
    where v1.id_customer = v2.id_customer
    and v2.date_sale > v1.date_sale
    group by v1.id_model, v2.id_model;
    I received:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2.....................................435 days
    ..............3................................4.....................................793 days
    But If I insert a new vehicle:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    7................................516....................3............ 16/08/2003
    And I execute the query now I receive:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2...........................435 days
    ..............1................................3...........................706 days
    ..............2................................3...........................239 days
    ..............3................................4...........................793 days
    It is NO correct because I don’t have the 1 (Source_model) to 3 (Target_model) combination in the Vehicles data!!! (I have 1 to 2 and 2 to 3 but NO 1 to 3!!!!).
    Then the query is not OK for me!
    Besides If I modify the Vehicle 7 data and put ID_Model = 2:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    7................................516....................2............ 16/08/2003
    I received:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2...........................525,33 days
    ..............2................................2...........................239 days
    ..............3................................4...........................793 days
    It is NO correct because the BUY_AVERAGE_TIME for 1 to 2 combination is 435 days (the same of the original query) because I aggregate only the combination 2 to 2 with the ID_VEHICLE 7
    Below I attach the examples scripts.
    Could you help me with this query, please?
    Thanks very much!
    CREATE TABLE VEHICLES
    ID_VEHICLE NUMBER(9),
    ID_CUSTOMER NUMBER(9),
    ID_MODEL NUMBER(9),
    DATE_SALE DATE
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    1, 123, 1, TO_Date( '05/21/2000 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    2, 459, 3, TO_Date( '08/16/2000 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    3, 123, 2, TO_Date( '06/28/2001 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    4, 516, 1, TO_Date( '09/09/2001 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    5, 459, 4, TO_Date( '10/18/2002 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    6, 516, 2, TO_Date( '12/20/2002 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    7, 516, 2, TO_Date( '08/16/2003 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    COMMIT;
    CREATE TABLE MODELS
    ID_MODELO NUMBER(9),
    MODEL_NAME VARCHAR2(25 BYTE)
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    1, 'MODEL 1');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    2, 'MODEL 2');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    3, 'MODEL 3');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    4, 'MODEL 4');
    COMMIT;
    CREATE TABLE CUSTOMERS
    ID_CUSTOMER NUMBER(9),
    NAME VARCHAR2(25 BYTE),
    LASTNAME VARCHAR2(25 BYTE)
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    123, 'Customer 123', 'A');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    459, 'Customer 459', 'B');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    516, 'Customer 516', 'C');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    318, 'Customer 318', 'D');
    COMMIT;

  • How to execute this SQL Query in ABAP Program.

    Hi,
    I have a string which is the SQL Query.
    How to execute this sql Query (SQL_STR) in ABAP Program.
    Code:-
    DATA: SQL_STR type string.
    SQL_STR = 'select * from spfli.'.
    Thanks in Advance,
    Vinay

    Hi Vinay
    Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
    REPORT dynamic_sql_example .
    DATA: BEGIN OF gt_itab OCCURS 1 ,
    line(80) TYPE c ,
    END OF gt_itab .
    DATA gt_restab TYPE .... .
    DATA gv_name(30) TYPE c .
    DATA gv_err(120) TYPE c .
    START-OF-SELECTION .
    gt_itab-line = 'REPORT generated_sql .' .
    APPEND gt_itab .
    gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
    APPEND gt_itab .
    gt_itab-line = SQL_STR .
    APPEND gt_itab .
    gt_itab-line = 'ENDFORM.' .
    APPEND gt_itab .
    GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
    PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
    IF FOUND .
    WRITE:/ gv_err .
    LOOP AT gt_result .
    WRITE:/ .... .
    ENDLOOP .
    *--Serdar

  • How to write the given query using 'ANY ' operator

    Hi,
    How to write the given query using 'ANY ' operator , I dont need to fetch to grade_master table twice in database, just need to fetch within the result set.
    SELECT dsg_code,dsg_name,dsg_grade FROM designation_master WHERE dsg_orgn='&&Orgn' and dsg_ctry='&&ctry'
    And dsg_loc ='&&loc' And dsg_oru = '&&oru' and dsg_grade in decode('&&radio_group',
    1, SELECT grd_code FROM grade_master WHERE grd_osm_code in (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&Orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'),
    2, SELECT grd_code FROM grade_master WHERE grd_osm_code > (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' and grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code),
    3, SELECT grd_code FROM grade_master WHERE grd_osm_code < (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'))
    thanks
    rincy

    Hi,
    One thing I understood my your issue is you want to perform, execution of query once or fetch the results sets my minimizing the number of times executions of queries. It would be hard for us to check in this way, atleast provide some temporary data and some business rules. Only I can IN, >, < (queries logical conditons on inner query)
    - Pavan Kumar N
    - ORACLE OCP - 9i/10g
    https://www.oracleinternals.blogspot.com

  • How to write a SQL query in SAP B1 2007 B with input parameters?

    How to write a SQL query in SAP B1 2007 B with input parameters, on execution of which will ask for some input value from the user and the values will be selected from a list such as item list?

    The syntax like
    SELECT * FROM OITM T0 WHERE T0.ItemCode = '[%0\]'
    Thanks,
    Gordon

  • Which planning function i have to use and how to write this planning fucnti

    Hi Bi Guru's,
    I have rolled out  BW SEM-BPS Planning Layout's for the Annual Budget in my organistaion.
    There are two levels of layout given for the each sales person.
    1)  Sales quantity to be entered Material and  country wise for all 12 months ( April 2009 to March 2010)
    2)  Rate per unit and to entered in second sheet, Material and country wise for the total qty entered in the first layout.
    Now i need to calculate the sales vlaue for each period and for the each material.
    Which planning function i have to use and how to write this planning fucntion.
    Please suggest me some solution ASAP.
    Thanks in Advance,
    Nilesh

    Hi Deepti,
    Sorry to trouble you...
    I require your help for the following scenario for caluclating Sales Value.
    I have Plan data in the following format.
    Country   Material    Customer    Currency    Fiscyear    Fiscper           Qty         Rate        Sales Value
    AZ          M0001      CU001          #             2009          001.2009        100.00                        
    AZ          M0001      CU002          #             2009          001.2009        200.00                        
    BZ          M0001      CU003          #             2009          001.2009        300.00
    BZ          M0001      CU003          #             2009          002.2009        400.00
    BZ          M0002      CU003          #             2009          002.2009        300.00
    AZ          M0001       #               USD          2009             #                                 10.00
    BZ          M0001       #               USD          2009             #                                 15.50
    BZ          M0002       #               USD          2009             #                                 20.00
    In the Above data the Rate lines are entered in the Second Layout, Where the user enters on the Country Material Level with 2009 value for FISCYEAR.
    I am facing problem with this type of data. 
    I want to store the sales value for each Material Qty.
    Please suggest some solution.
    Re
    Nilesh

  • Hi, I've checked how to use kannada keyboard in Yosemite. But, there are some 'vattu forms' and other grammar in Kannada language that I don't know how to use it. For eg, Preetiya taatanige nimma muddu mommagalu maduva namaskara? How to write this?

    Hi, I've checked how to use Kannada keyboard in Yosemite. But, there are some 'vattu forms' and other grammar in Kannada language that I don't know how to use it. I know how to change between the keyboards and can also view keyboard. However, For eg, 'Preetiya taatanige nimma muddu mommagalu maduva namaskara' How to write this? If anybody can answer this, very much appreciated.
    Thanks in advance for your reply.

    In general, you need to use the "f" (kannada qwerty keyboard) or "d" key (kannada) between letters to make special forms.  Also you may need to adjust the typography settings of the font, which is done by doing Format > Font > Show Fonts > Gear Wheel > Typography as shown below.  If you can provide screenshots or more detailed info on things you cannot make, I can perhaps help.
    It is important to note that MS Word for Mac does not support Indic scripts -- any other app should work OK.

  • How to write a sql query to retrieve data entered in the past 2 weeks

    Hi,
    I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
    Thanks in advance.

    This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
    Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
    I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate".

  • How to write this assignment in oom way(long)

    i try to write a new class, but i am not very sure if there is only one new class, I shall write a Movie class or a Ticket class?
    this is my Movie class, if I also want to write a new Ticket class. and still i don't know how to write
    because the Ticket class uses some of the attributes of the Movie class such as start time, Movie.name, as in this situation the relation
    between Ticket and Movie is still aggregation, or become a generalization?
    and how to represent that a Movie can have many Tickets? I shall write a buy-ticket method inside the Ticket class or Movie class.
    (are there any thing not right with this movie class? thanks)
    ============================
    class Movie
         String name;
         String startTime;
         String [] coupleChair=new String[11];//start from 1 to 10
         String [] singleChair=new String[11];//start from 1 to 10     
         public Movie(String str1st)
              this.name=str1st;
         public Movie(String str1st, String str2nd)
              this.name=str1st;
              this.startTime=str2nd;
         public String buyA_Single_Ticket()
              int i=1;
              do
                   if(this.singleChair!="sold")
                        this.singleChair[i]="sold";
                        return "You seat is Single Seat No."+i+"\n Enjoy the movie :)";
                   else i++;
              while(i<=10);//when i==11 jump out
              return "Sorry, all Single seats have been sold Out";
         public String buyA_Couple_Ticket()
              int i=1;
              do
                   if(this.coupleChair[i]!="sold")
                        this.coupleChair[i]="sold";
                        return "You seat is Couple Seat No."+i+"\n Enjoy the time ;)";
                   else i++;
              while(i<=10);//when i==11 jump out
              return "Sorry, all Couple seats have been sold Out";
    }//end class
    ============================
    this is the question
    A small ABC cinema has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a Java application to assign seats on each movie show on the day (capacity: 20 seats for 1 movie).
    Your program should display the following alternatives: ��Please type 1 for couple seat section�� and ��Please type 2 for normal seat section��. If the user types 1, your program should assign one seat in the couple seat section (seats 1 �C 10). If the person types 2, your program should assign a seat in the normal seat (seats 11 �C 20). Your program should also prompt for the movie time and movie name.
    Your program should then display:
    I.     The person��s seat number
    II.     Whether it is a couple seat or normal seat of the cinema
    III.     Time, date, movie name
    Your program should never assign a seat that has already been assigned. When the normal seat section is full, your program should ask the person if it is acceptable to be placed in the couple seat section (and vice versa). If yes, make the appropriate seat assignment. If no, print the message ��Next show is in 3 hours time.��
    (it is just a small test on my OOM learning, I know it is not necessary to make it so complex.)

    Break down your problem into discrete chunks. The more you practice this, the more your initial thoughts will resemble the eventual objects that you will create.
    Let's take address a few of your issues:
    What has the start time? Is it the ticket or the movie? (Hint: Would someone ever print you out a ticket with a different start time than the movie's?)
    If ticket and movie share some attributes, then you can either use inheritance or composition/delegation. In this instance, what makes more sense to you? Is a ticket a movie or vice versa? Or is a ticket simply related to a movie?
    If a given object can contain several instances of another object, you will want to use either an array or a collection, probably List in this instance.
    Why is there no Theater object? A movie may play at multiple theaters. Each theater has a capacity (in terms of total seats and number already booked). This does not really have anything to do with the movie. It is the Theater that you are booking. It may also have which movies are showing at which time.
    Your notion of 'couple' booking seems strange. Why not have a concept like 'consecutive seats required'? That way, your design is more flexible and you can still accomodate couples.That should get you started. Best of luck.
    - Saish

  • How to write EJB-QL query with IN notation and list values EJB3.0?

    hi,
    I would like to write an EJB-QL query where the query would return the objects whose name equals to one of the names in the list.
    SELECT DISTINCT OBJECT(feature) FROM MAPSHEET_LOCK feature WHERE feature.name IN ?1
    For ?1 I would like to pass in a list. How can I write this query?
    Thanks

    List<String> names;
    StringBuilder sb = new StringBuilder("SELECT DISTINCT OBJECT(feature) FROM MAPSHEET_LOCK feature WHERE feature.name IN (");
    String separator = "";
    for (String name : names) {
      sb.append(separator);
       sb.append("'");
       sb.append(name);
       sb.append("'");
       separator = ", ";
    sb.append(")");
    String ejbql = sb.toString();
    // Code for execute query
    ....Message was edited by:
    Rulas

Maybe you are looking for

  • Help on dynamically loading of simple classes - ClassLoader

    Hello, does somebody know how to load simple classes with java.lang.ClassLoader in a stateless session bean running on SneakPreview 6.40? i found many solutions for j2ee servers on the net but no one works. i always get a ClassNotFoundException but i

  • How to upgrade Update rules to Transformations

    Hi   My is to Update/Upgrade UPDATE RULES to TRANSFORMATIONS   How can i do it in BI 7.0.   Is there any programe that will upgrade the update rules to transformations Thanks

  • Two cordless systems in one house?

    I have a home phone line on which we have 4 Freestyle 2500 DECT handsets. However, I also have a second line which I use for my business - trouble is, I'd like to have more than one handset for that too - does anyone know if there is a way I can buy

  • Release Strategy with New Class and Char.

    Dear All, I have facing problem when creating the new release strategy for different country. i have create new Characteristic and class for new Release streategy. when i going to add in Release group.. system giving the error. Diagnosis Here you can

  • NW07 on 32 or 64 bit platform?

    Hello, I have to install NW 07 and the Oracle DB on a Windows server. This server is equiped with 2 quadcore processors and 10go of RAM. Is it better to run a NW07 instance on 32 or 64 bit platform ? Oracle ? Ths instance will load data from R/3 32bi