Help with this query please

Hi there, 
These are the sample values
declare @table table
Name varchar(50),
flag int
insert into @table
values('Matt', 0),
('George', 0),
('George', 1),
('Lucas', 0),
('Jerome', 0),
('Jerome', 1)
I want to select out where George and Jerome where flag = 0 but leave the records from the same names where flag = 1. All others that only have flag = 0, should stay. So only the names that repeat and have both flag, flag = 0 zero should be selected out.
Thanks for your help.

So desired output is ????
George 0
Jerome 0
declare @table table
Name varchar(50),
flag int
insert into @table
values('Matt', 0),
('George', 0),
('George', 1),
('Lucas', 0),
('Jerome', 0),
('Jerome', 1)
select name,min(flag) flag,count(*) from @table
group by name
having count(*)>1
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • Can any one help with this query please

    I have a table something as below
    Things_t
    Things Characteristic Char Value
    Item 1 Colour Red
    Item 1 Packaging
    Item 2 Shape Square
    Item 2 Brand Spunk
    Now i want to reterive an item with none of its char values as Null. Using the query “ select distinct things from things_t where char value is Null ” will fetch the item 1 also together with item 2. i want to fetch a record from thing for which none of the char values are Null such as Item 2. Can you please help me with this query.

    Try this:
    WITH t AS
    (SELECT 1 item_id, 17436 chr_id, 14225034 chr_val_id FROM dual UNION
    SELECT 1 item_id, 39 chr_id, 14276173 chr_val_id FROM dual UNION
    SELECT 1 item_id, 17774 chr_id, NULL chr_val_id FROM dual UNION
    SELECT 1 item_id, 265 chr_id, 20502978 chr_val_id FROM dual UNION
    SELECT 1 item_id, 16978 chr_id, 797233 chr_val_id FROM dual UNION
    SELECT 1 item_id, 13092 chr_id, 5666917 chr_val_id FROM dual UNION
    SELECT 1 item_id, 15228 chr_id, 1209758 chr_val_id FROM dual UNION
    SELECT 2 item_id, 112 chr_id,  12705342 chr_val_id FROM dual UNION
    SELECT 2 item_id, 6945 chr_id, NULL chr_val_id FROM dual UNION
    SELECT 2 item_id, 70 chr_id, 12597376 chr_val_id FROM dual UNION
    SELECT 2 item_id, 16832 chr_id, NULL chr_val_id FROM dual UNION
    SELECT 2 item_id, 7886 chr_id, 9588619 chr_val_id FROM dual UNION
    SELECT 2 item_id, 6986 chr_id, 2659351 chr_val_id FROM dual UNION
    SELECT 3 item_id, 9531 chr_id, 8910943 chr_val_id FROM dual UNION
    SELECT 3 item_id, 9798 chr_id, 8717531 chr_val_id FROM dual UNION
    SELECT 3 item_id, 17446 chr_id, 12266441 chr_val_id FROM dual UNION
    SELECT 3 item_id, 4830 chr_id, 13683090 chr_val_id FROM dual UNION
    SELECT 3 item_id, 9518 chr_id, 834772 chr_val_id FROM dual UNION
    SELECT 3 item_id, 11031 chr_id, 20233753 chr_val_id FROM dual UNION
    SELECT 3 item_id, 12564 chr_id, 2282478 chr_val_id FROM dual)
    SELECT DISTINCT item_id
    FROM   t
    MINUS
    SELECT DISTINCT item_id
    FROM   t
    WHERE  chr_val_id IS NULLOr this:
    SELECT item_id
    FROM  (SELECT   item_id,
                    MIN(NVL(chr_val_id, -1)) min_chr_val_id
           FROM     t
           GROUP BY item_id)
    WHERE  min_chr_val_id != -1Edited by: lee200 on Oct 15, 2012 9:22 AM

  • SQL I need help with this query Please help

    List the names of all the products whose weight unit measure is “Gram”.  Order the list by product name.  Do not use JOINS, but use the IN clause with a sub-query.
    select Name
    from UnitMeasure
    where Name= 'Gram'
    order by Name
    I did this, but it seem that the requirement is different.

    As a guess:
    Select Name from Product
    where UnitMeasure in (Select Name from unitmeasure where name = 'Gram')
    Andy Tauber
    Data Architect
    The Vancouver Clinic
    Website | LinkedIn
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
    "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

  • Please need help with this query

    Hi !
    Please need help with this query:
    Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
    Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
    select distinct a.id,
    create_date,
    a.loanid,
    a.rate,
    a.pays,
    a.gracetime,
    a.emailtosend,
    d.first_name,
    d.last_name,
    a.user_id
    from CLAL_LOANCALC_DET a,
    loan_Calculator b,
    bv_user_profile c,
    bv_mr_user_profile d
    where b.loanid = a.loanid
    and c.NET_USER_NO = a.resp_id
    and d.user_id = c.user_id
    and a.is_partner is null
    and a.create_date between
    TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
    TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    order by a.create_date

    Perhaps something like this...
    select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
    from (
          select distinct a.id,
                          create_date,
                          a.loanid,
                          a.rate,
                          a.pays,
                          a.gracetime,
                          a.emailtosend,
                          d.first_name,
                          d.last_name,
                          a.user_id,
                          max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
          from CLAL_LOANCALC_DET a,
               loan_Calculator b,
               bv_user_profile c,
               bv_mr_user_profile d
          where b.loanid = a.loanid
          and   c.NET_USER_NO = a.resp_id
          and   d.user_id = c.user_id
          and   a.is_partner is null
          and   a.create_date between
                TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
                TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    where create_date = max_create_date
    order by create_date

  • HT1338 I have a macbook Pro i7 mid november 2010. I am wondering if i can exchange my notebook with the latest one. Can anyone help me out with this query please.

    I have a macbook Pro i7 mid november 2010. I am wondering if i can exchange my notebook with the latest one. Can anyone help me out with this query please.

    You can sell your existing computer using eBay, Craigslist or the venue of your choice. You could then use the proceeds to purchase a new computer.

  • I need help with this script please ASAP

    So I need this to work properly, but when ran and the correct answer is chosen the app quits but when the wrong answer is chosen the app goes on to the next question. I need help with this ASAP, it is due tommorow. Thank you so much for the help if you can.
    The script (Sorry if it's a bit long):
    #------------Startup-------------
    display dialog "Social Studies Exchange Trviva Game by Justin Parzik" buttons {"Take the Quiz", "Cyaaaa"} default button 1
    set Lolz to (button returned of the result)
    if Lolz is "Cyaaaa" then
    killapp()
    else if Lolz is "Take the Quiz" then
              do shell script "say -v samantha Ok starting in 3…2…1…GO!"
    #------------Question 1-----------
              display dialog "Around age 11, many boys left their fathers to become…" buttons {"Scholars", "Warriors", "Apprentices"}
              set A1 to (button returned of the result)
              if A1 is "Apprentices" then
                        do shell script "say -v samantha Correct Answer"
              else
                        do shell script "say -v samantha Wrong Answer"
      #----------Question 2--------
                        display dialog "Most children were taught
    to read so that they could understand the…" buttons {"Music of Mozart", "Bible", "art of cooking"}
                        set A2 to (button returned of the result)
                        if A2 is "Bible" then
                                  do shell script "say -v samantha Correct Answer"
                        else
                                  do shell script "say -v samantha Wrong Answer"
      #------------Question 3---------
                                  display dialog "In the 1730s and 1740s, a religious movement called the_______swept through the colonies." buttons {"Glorius Revolution", "Great Awakening", "The Enlightenment"}
                                  set A3 to (button returned of the result)
                                  if A3 is "Great Awakening" then
                                            do shell script "say -v samantha Correct Answer"
                                  else
                                            do shell script "say -v samantha Wrong Answer"
      #-----------Question 4--------
                                            display dialog "_______ was
    a famous American Enlightenment figure." buttons {"Ben Franklin", "George Washington", "Jesus"}
                                            set A4 to (button returned of the result)
                                            if A4 is "Ben Franklin" then
                                                      do shell script "say -v samantha Correct Answer"
                                            else
                                                      do shell script "say -v samantha Wrong Answer"
      #----------Question 5-------
                                                      display dialog "______ ownership gave colonists political rights as well as prosperity." buttons {"Land", "Dog", "Slave"}
                                                      set A5 to (button returned of the result)
                                                      if A5 is "Land" then
                                                                do shell script "say -v samantha Correct Answer"
                                                      else
                                                                do shell script "say -v samantha Wrong Answer"
      #---------Question 6--------
                                                                display dialog "The first step toward guaranteeing these rights came in 1215. That
    year, a group of English noblemen forced King John to accept the…" buttons {"Declaration of Independence", "Magna Carta", "Constitution"}
                                                                set A6 to (button returned of the result)
                                                                if A6 is "Magna Carta" then
                                                                          do shell script "say -v samantha Correct Answer"
                                                                else
                                                                          do shell script "say -v samantha Wrong Answer"
      #----------Question 7--------
                                                                          display dialog "England's cheif lawmaking body was" buttons {"the Senate", "Parliament", "King George"}
                                                                          set A7 to (button returned of the result)
                                                                          if A7 is "Parliament" then
                                                                                    do shell script "say -v samantha Correct Answer"
                                                                          else
                                                                                    do shell script "say -v samantha Wrong Answer"
      #--------Question 8-----
                                                                                    display dialog "Pariliament decided to overthrow _______ for not respecting their rights" buttons {"King James II", "King George", "King Elizabeth"}
                                                                                    set A8 to (button returned of the result)
                                                                                    if A8 is "King James II" then
                                                                                              do shell script "say -v samantha Correct Answer"
                                                                                    else
                                                                                              do shell script "say -v samantha Wrong Answer"
      #--------Question 9------
                                                                                              display dialog "Parliament named ___ and ___ as England's new monarchs in something called ____." buttons {"William/Mary/Glorius Revolution", "Adam/Eve/Great Awakening", "Johhny/Mr.Laphalm/Burning of the hand ceremony"}
                                                                                              set A9 to (button returned of the result)
                                                                                              if A9 is "William/Mary/Glorius Revolution" then
                                                                                                        do shell script "say -v samantha Correct Answer"
                                                                                              else
                                                                                                        do shell script "say -v samantha Wrong Answer"
      #---------Question 10-----
                                                                                                        display dialog "After accepting the throne William and Mary agreed in 1689 to uphold the English Bill of _____." buttons {"Money", "Colonies", "Rights"}
                                                                                                        set A10 to (button returned of the result)
                                                                                                        if A10 is "Rights" then
                                                                                                                  do shell script "say -v samantha Correct Answer"
                                                                                                        else
                                                                                                                  do shell script "say -v samantha Wrong Answer"
      #---------Question 11------
                                                                                                                  display dialog "By the late 1600s French explorers had claimed the ___ River Valey" buttons {"Mississippi", "Ohio", "Hudson"}
                                                                                                                  set A11 to (button returned of the result)
                                                                                                                  if A11 is "Ohio" then
                                                                                                                            do shell script "say -v samantha Correct Answer"
                                                                                                                  else
                                                                                                                            do shell script "say -v samantha Wrong Answer"
      #------Question 12---------
                                                                                                                            display dialog "______ was sent to ask the French to leave 'English Land'." buttons {"Johhny Tremain", "George Washington", "Paul Revere"}
                                                                                                                            set A12 to (button returned of the result)
                                                                                                                            if A12 is "George Washington" then
                                                                                                                                      do shell script "say -v samantha Correct Answer"
                                                                                                                            else
                                                                                                                                      do shell script "say -v samantha Wrong Answer"
      #---------Question 13-------
                                                                                                                                      display dialog "_____ proposed the Albany Plan of Union" buttons {"George Washingon", "Ben Franklin", "John Hancock"}
                                                                                                                                      set A13 to (button returned of the result)
                                                                                                                                      if A13 is "Ben Franklin" then
                                                                                                                                                do shell script "say -v samantha Correct Answer"
                                                                                                                                      else
                                                                                                                                                do shell script "say -v samantha Wrong Answer"
      #--------Question 14------
                                                                                                                                                display dialog "The __________ declared that England owned all of North America east of the Mississippi" buttons {"Proclomation of England", "Treaty of Paris", "Pontiac Treaty"}
                                                                                                                                                set A14 to (button returned of the result)
                                                                                                                                                if A14 is "" then
                                                                                                                                                          do shell script "say -v samantha Correct Answer"
                                                                                                                                                else
                                                                                                                                                          do shell script "say -v samantha Wrong Answer"
      #-------Question 15-------
                                                                                                                                                          display dialog "Braddock was sent to New England so he could ______" buttons {"Command an attack against French", "Scalp the French", "Kill the colonists"}
                                                                                                                                                          set A15 to (button returned of the result)
                                                                                                                                                          if A15 is "Command an attack against French" then
                                                                                                                                                                    do shell script "say -v samantha Correct Answer"
                                                                                                                                                          else
                                                                                                                                                                    do shell script "say -v samantha Wrong Answer"
      #------TheLolQuestion-----
                                                                                                                                                                    display dialog "____ is the name of the teacher who runs this class." buttons {"Mr.White", "Mr.John", "Paul Revere"} default button 1
                                                                                                                                                                    set LOOL to (button returned of the result)
                                                                                                                                                                    if LOOL is "Mr.White" then
                                                                                                                                                                              do shell script "say -v samantha Congratulations…you…have…common…sense"
                                                                                                                                                                    else
                                                                                                                                                                              do shell script "say -v alex Do…you…have…eyes?"
                                                                                                                                                                              #------END------
                                                                                                                                                                              display dialog "I hope you enjoyed the quiz!" buttons {"I did!", "It was horrible"}
                                                                                                                                                                              set endmenu to (button returned of the result)
                                                                                                                                                                              if endmenu is "I did!" then
                                                                                                                                                                                        do shell script "say -v samantha Your awesome"
                                                                                                                                                                              else
                                                                                                                                                                                        do shell script "say -v alex Go outside and run a lap"
                                                                                                                                                                              end if
                                                                                                                                                                    end if
                                                                                                                                                          end if
                                                                                                                                                end if
                                                                                                                                      end if
                                                                                                                            end if
                                                                                                                  end if
                                                                                                        end if
                                                                                              end if
                                                                                    end if
                                                                          end if
                                                                end if
                                                      end if
                                            end if
                                  end if
                        end if
              end if
    end if

    Use code such as:
    display dialog "Around age 11, many boys left their fathers to become…" buttons {"Scholars", "Warriors", "Apprentices"}
    set A1 to (button returned of the result)
    if A1 is "Apprentices" then
    do shell script "say -v samantha Correct Answer"
    else
    do shell script "say -v samantha Wrong Answer"
    return
    end if
    #----------Question 2--------
    display dialog "Most children were taught to read so that they could understand the…" buttons {"Music of Mozart", "Bible", "art of cooking"}
    set A2 to (button returned of the result)
    if A2 is "Bible" then
    do shell script "say -v samantha Correct Answer"
    else
    do shell script "say -v samantha Wrong Answer"
    return
    end if
    (90444)

  • Pls help with this query

    Hello
    If I run the following query I correctly get a sum of the invoices for a particular BP for Jan 09
    SELECT T1.[SlpName], T0.[CardCode], SUM(CASE WHEN  T2.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T2.[DocTotal] -  T2.[VatSum]) ELSE 0 END) AS 'JAN 09' FROM OCRD T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN OINV T2 ON T0.CardCode = T2.CardCode WHERE T0.[CardCode] = 'KEY065' GROUP BY T0.[CardCode], T1.[SlpName]
    However I need the value of credit notes to be reflected in the figure so I amended the query to be:
    SELECT T1.[SlpName], T0.[CardCode], SUM(CASE WHEN  T2.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T2.[DocTotal] -  T2.[VatSum])ELSE 0 END) - SUM(CASE WHEN  T3.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T3.[DocTotal] -  T3.[VatSum]) ELSE 0 END) AS 'JAN 09' FROM OCRD T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN OINV T2 ON T0.CardCode = T2.CardCode INNER JOIN ORIN T3 ON T0.CardCode = T3.CardCode WHERE T0.[CardCode] = 'KEY065' GROUP BY T0.[CardCode], T1.[SlpName]
    When I run this query the output is incorrect ................ Is the fault to do with my JOINS?
    Thanks

    Hi Just to clarify
    This query, which just totals any invoices for a BP for January, correctly returns a value of £9660.44 :
    SELECT T1.[SlpName], T0.[CardCode], SUM(CASE WHEN  T2.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T2.[DocTotal] -  T2.[VatSum]) ELSE 0 END) AS 'JAN 09' FROM OCRD T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN OINV T2 ON T0.CardCode = T2.CardCode  WHERE T0.[CardCode] = 'KEY065' GROUP BY T0.[CardCode], T1.[SlpName]
    This next query, which just totals any credit notes for a BP in January, correctly returns a value of £567.73 :
    SELECT T1.[SlpName], T0.[CardCode], SUM(CASE WHEN  T3.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T3.[DocTotal] -  T3.[VatSum]) ELSE 0 END) AS 'JAN 09' FROM OCRD T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN ORIN T3 ON T0.CardCode = T3.CardCode WHERE T0.[CardCode] = 'KEY065' GROUP BY T0.[CardCode], T1.[SlpName]
    I want a query which return a value of 9660.44 minus 567.73 (ie £9092.71)
    My original effort at this returned -£82,608.65 !!!!!!!!!
    and Gordon's amended version returned -£40,281.74 !!!!!
    Thanks for your patience
    Steve

  • I have noticed that Safari does not support some HTML commands on apple operating systems. Can anyone help with this issue please?

    I have noticed that Safari does not support some HTML commands on this operating platform. Can anybody throw any light on this issue please?

    Examples.

  • Please help with this query!

    Hi All,
    I have this this table:
    Term Grade
    term_A A
    term_A A
    term_A B
    term_A B
    term_B D
    term_B F
    term_B F
    term_C C
    How do I display so that it appears this way?
    term_A A 2
    term_A B 2
    term_B D 1
    term_B F 2
    term_C C 1
    Thank you. Appreciate all the help!

    Please read about [url http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/functions001.htm#sthref962]aggregate functions in the manual.
    Regards,
    Rob.

  • Need help with this query

    Hi,
    I am using SQL Server 2008 Enterprise edition 64 bit on Windows serer 2008 enterprise edition 64 bit.
    The below query works fine. I am trying to rewrite the code without using the sub query. In the end i should get the same results for both the query which we are going to rewrite and the below mentioned query.
    Can any help me please.
    SELECT
    t1.DOCUMENT_NO,
    RTRIM(CAST(t1."ENVIRONMENT_CD" AS VARCHAR(5))) + '*' + RTRIM(CAST(t1."ORDER_NO" AS VARCHAR(25)))
    +
    CASE WHEN (SELECT COUNT(DISTINCT S1.TEST_REPORTING_MATERIAL_SID)
    FROM dbo.TBLTEST S1 ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
    WHERE S1.TEST_REPORTING_MATERIAL_SID > 0
    AND S1.COMPANY_CD = T1.COMPANY_CD AND S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
    AND S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
    AND S1.ORDER_NO = T1.ORDER_NO) > 1 THEN
    RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS VARCHAR(10)))
    ELSE
    END as sum_key,
    t1.SALES_ANALYSIS_CD
    FROM
    dbo.TBLTEST_ALL T1
    WHERE
    t1.TIME_SID >= 20001001 ;
    I tried to use a left outer Join , it did not work out. I tried to take the subquery and assign it to a variable and use in the above mentioned query. But i am not getting the same results.
    I don't want to use the above query so i am planning to rewrite the code.
    Thank You,

    I doubt that the query you posted works fine, because:
    FROM dbo.TBLTEST S1 ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
    This is a syntax error. I will have to assume that your inteded query reads:
    SELECT t1.DOCUMENT_NO,
           rtrim(cast(t1."ENVIRONMENT_CD" AS varchar(5))) + '*' +
           rtrim(cast(t1."ORDER_NO" AS varchar(25))) +
          CASE WHEN (SELECT COUNT(DISTINCT S1.TEST_REPORTING_MATERIAL_SID)
                     FROM   dbo.TBLTEST S1
                     WHERE  S1.DOCUMENT_NO = T1.DOCUMENT_NO
                       AND  S1.TEST_REPORTING_MATERIAL_SID > 0
                       AND  S1.COMPANY_CD = T1.COMPANY_CD
                       AND  S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
                       AND  S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
                       AND  S1.ORDER_NO = T1.ORDER_NO) > 1 THEN
                     RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS VARCHAR(10)))
               ELSE  '*-'
          END as sum_key, t1.SALES_ANALYSIS_CD
    FROM   dbo.TBLTEST_ALL T1
    WHERE  t1.TIME_SID >= 20001001
    Here is a query with a left join. Whether it is actually better than the one you have I am not sure.
    SELECT t1.DOCUMENT_NO,
           rtrim(cast(t1."ENVIRONMENT_CD" AS varchar(5))) + '*' +
           rtrim(cast(t1."ORDER_NO" AS varchar(25))) +
          CASE WHEN S1."EXISTS" IS NOT NULL
               THEN  RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS varchar(10)))
               ELSE  '*-'
          END as sum_key, t1.SALES_ANALYSIS_CD
    FROM   dbo.TBLTEST_ALL T1
    LEFT   JOIN (SELECT 1 AS "EXISTS"
                 FROM   dbo.TBLTEST
                 WHERE  TEST_REPORTING_MATERIAL_SID > 0
                 GROUP  BY DOCUMENT_NO, COMPANY_CD, INVOICE_SEQ_NO,
                           DOCUMENT_ITEM_NO, ORDER_NO
                 HAVING COUNT(DISTINCT TEST_REPORTING_MATERIAL_SID) > 1) AS S1
             ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
           AND  S1.COMPANY_CD = T1.COMPANY_CD
           AND  S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
           AND  S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
           AND  S1.ORDER_NO = T1.ORDER_NO
    WHERE  t1.TIME_SID >= 20001001
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Can anyone help with this query

    create table customer(
    customer_email varchar(100) not null
    ,cust_id int not null
    ,constraint pk__customer primary key clustered(cust_id)
    Please help ASAP
    create table purchase (
    purchase_id int not null identity(1,1)
    ,cust_id int not null references customer(cust_id)
    ,product_name varchar(200) not null
    ,amount int not null
    ,constraint pk__purchase primary key clustered (purchase_id)
    Write a query that returns one row per customer with the following columns. Don't forget about customers with no purchases.
    customer_email
    qty of purchase
    sum of purchase amount

    Homework deadline looming?
    This will work in versions of Oracle from 9 up, and in all versions of Sybase/ SQL Server (which you seem to wnat based on the CREATE TABLE syntax).
    SELECT customer_email, COUNT(*) number_purchaes, SUM(amount) total_purchases
    FROM customer c
         LEFT OUTER JOIN purchases p ON c.cust_id = p.cust_id
    GROUP BY customer_emailTTFN
    John

  • Help with this problem please GasPump.java

    I've been working on this program for a week now and i have not gotten it to complie yet. Could anybody help me out? Your help would be greatly appreciated. Thanks.
    public class GasPump {
          double pricePerGallon;
          double gallons;
          int fuelType;
          int paymentType;
          float washPrice;
          String fuelName;
           public GasPump ( )  
             { pricePerGallon = 2.699; }
           public GasPump ( double price)  
             { pricePerGallon = price; }        
           public void setCost(double cost)   
             { double pricePerGallon  = cost; }
           double  getCost( )
             { return pricePerGallon; }
           public setGrade(int fuelType)
             { String fuelName;
            switch (fuelType)
                   case 1:    fuelName = ?Regular Unleaded?
                                  break;
                   case 2:    fuelName = ?Mid grade Unleaded?
                                  break;
                   case 3:    fuelName = ?Super Unleaded?
                                  break;
                   case 4:    fuelName = ?Diesel?
                                  break;
                   case 5:    fuelName = ?Natural Gas?
                                  break;
                   default:   System.out.println(?Unknown fuel type? + fuelType);
                               fuelName = ?Unknown?;
                   public String getGrade ( )
                   { return fuelName; }
                   double calcBill (double gallons)
                   { return(pricePerGallon * gallons); }
                   void paymentMethod(int  paymentType)    
                    if (paymentType  == 1)
                   payInsideMethod();
                    else
                          if (paymentType == 2)
                    payOutsideMethod();
                          else
                        if (paymentType == 3)
                       payInsideMethod ( );   
                          else
                     System.out.println(?Unknown payment type?);
                void payInsideMethod( )
                     System.out.println(?Pay cashier inside the gas station?);
                void payOutsideMethod( )
                System.out.println(?Please pay with your credit card ?);
               float   carWash (int washType)
                 washPrice = 0.00f;       
                  if (washType == 1)
                    washPrice = 7.00f;   
                      else
                  if (washType == 2)
                             washPrice = 8.00f; 
                  else
                            System.out.println(?Unknown wash type?);
                      return  (float)washPrice;   
                       void printReceipt ( )  
                        /*     System.out.println(fuelName + ? ? +gallons + ? Gallons purchased at $ ? + 
                               pricePerGallon + ? per gallon ? + ? Total cost is:  ? + 
                               pricePerGallon * gallons + ? Total bill is $ :" +
                               ((pricePerGallon * gallons) + washPrice)); */
                           System.out.printf("%s %.2f Gallons purchased at $%.2f per gallon.\nTotal
                  cost is: %.2f",
                                               fuelName, gallons, pricePerGallon, pricePerGallon *
                  gallons);
                       System.out.printf(" Total bill is $: %.2f", ((pricePerGallon * gallon) +
               washPrice));
               }

    sorry my compile errors read
    GasPump.java:31: illegal character: \8220
             case 3:    fuelName = ?Super Unleaded?;
                                   ^
    GasPump.java:31: illegal character: \8221
             case 3:    fuelName = ?Super Unleaded?;
                                                  ^
    GasPump.java:33: illegal character: \8220
             case 4:    fuelName = ?Diesel?;
                                   ^
    GasPump.java:33: illegal character: \8221
             case 4:    fuelName = ?Diesel?;
                                          ^
    GasPump.java:35: illegal character: \8220
             case 5:    fuelName = ?Natural Gas?;
                                   ^
    GasPump.java:35: illegal character: \8221
             case 5:    fuelName = ?Natural Gas?;
                                               ^
    GasPump.java:37: illegal character: \8220
            default:   System.out.println(?Unknown fuel type? + fuelType);
                                          ^
    GasPump.java:37: illegal character: \8221
            default:   System.out.println(?Unknown fuel type? + fuelType);
                                                            ^
    GasPump.java:37: ')' expected
            default:   System.out.println(?Unknown fuel type? + fuelType);
                                                                         ^
    GasPump.java:38: illegal character: \8220
                               fuelName = ?Unknown?;
                                          ^
    GasPump.java:38: illegal character: \8221
                               fuelName = ?Unknown?;
                                                  ^
    GasPump.java:59: illegal character: \8220
                              System.out.println(?Unknown payment type?);
                                                 ^
    GasPump.java:59: illegal character: \8221
                              System.out.println(?Unknown payment type?);
                                                                      ^
    GasPump.java:59: ')' expected
                              System.out.println(?Unknown payment type?);
                                                                        ^
    GasPump.java:64: illegal character: \8220
                      System.out.println(?Pay cashier inside the gas station?);
                                         ^
    GasPump.java:64: illegal character: \8221
                      System.out.println(?Pay cashier inside the gas station?);
                                                                            ^
    GasPump.java:64: ')' expected
                      System.out.println(?Pay cashier inside the gas station?);
                                                                              ^
    GasPump.java:69: illegal character: \8220
                      System.out.println(?Pay at the pump with credit card ?);
                                         ^
    GasPump.java:69: illegal character: \8221
                      System.out.println(?Pay at the pump with credit card ?);
                                                                           ^
    GasPump.java:69: ')' expected
                      System.out.println(?Pay at the pump with credit card ?);
                                                                             ^
    GasPump.java:82: illegal character: \8220
                             System.out.println(?Unknown wash type?);
                                                ^
    GasPump.java:82: illegal character: \8221
                             System.out.println(?Unknown wash type?);
                                                                  ^
    GasPump.java:82: ')' expected
                             System.out.println(?Unknown wash type?);
                                                                    ^
    GasPump.java:94: unclosed string literal
                           System.out.printf("%s %.2f Gallons purchased at $%.2f per
    gallon.\nTotal
                                             ^
    GasPump.java:95: unclosed string literal
                   cost is: %.2f",
                                ^
    GasPump.java:97: ')' expected
                     gallons);
                             ^
    26 errorsBasically wherever I have a quotation mark or a semi-colon there is a error there. I just started programming so im still trying to get the hang of it

  • Possibly corrupt prefs.js file. Need help with this file please.

    I've been having a problem with sending/receiving text messages in Yahoo Messenger and I think I've narrowed it to the prefs.js file in Firefox. I'm using Firefox 3.6.25 on Windows XP sp3. The Yahoo Messenger window would not open when the appropriate mobile phone link was clicked. I uninstalled/reinstalled flash without change. I cleared cache, etc., without change. I created a new Firefox profile and I was able to get the Yahoo Messenger window to open. When I copied the prefs.js file from the old profile to the new profile, I encountered the problem again. I opened the prefs.js file with wordpad and noticed that editing should occur in about:config in the currently running Firefox browser. I briefly compared the two about:config tabs from the working profile and the non-working profile. They were significantly different. How do I make a copy of one so that I can paste it into wordpad and make the editing of the other one easier? Where can I find information about the individual parameters and their settings?

    Hi,
    Please see [[http://kb.mozillazine.org/About:config_entries this.]
    [http://kb.mozillazine.org/About:config about:config]
    You can try to '''Reset all user preferences to Firefox defaults:''' and '''Make Changes and Restart''' in the [https://support.mozilla.org/en-US/kb/Safe%20Mode Firefox Safe Mode] start screen which would also hopefully solve the issue. You can also try to manually '''Reset''' to defaults the modified entries by right-clicking on the bold entries (user set) in about:config. Clicking on the '''Status''' column header would sort the entries between user set (modified) and the defaults.
    An easy way would be to create a [https://support.mozilla.org/en-US/kb/Managing-profiles new profile] and [https://support.mozilla.org/en-US/kb/Recovering%20important%20data%20from%20an%20old%20profile?s=profile&r=1&e=sph&as=s copy/transfer the needed personal data] from the old profile and start using the new profile. You can then delete or troubleshoot the old proile. Firefox stores your personal data and settings in [http://kb.mozillazine.org/Profile_folder another location (profile folder)] separate from its [http://kb.mozillazine.org/Installation_directory folders/files]. A new profile would have the default Firefox settings in '''Tools''' ('''Alt''' + '''T''') > [https://support.mozilla.org/en-US/kb/Options%20window Options] and [http://kb.mozillazine.org/About:config about:config], and usually would also be empty of '''Extensions''' and themes ('''Appearance''') in '''Tools''' > '''Add-ons''', and their settings. Also, a new profile would have no previous stored website cache/cookies/data/preferences: '''Tools''' > [https://support.mozilla.org/en-US/kb/Clear%20Recent%20History '''Clear Recent History'''].
    [https://support.mozilla.org/en-US/kb/Profiles?s=profile&r=2&e=sph&as=s Profiles Howto]
    [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder & Files]

  • Help with one query ( Please reply)

    Oracle version : 11.2.0.2.0
    I have a table with the following set of rows
    with Table_dm AS
    ( select 1 month_no ,'wk1' week, 120 DM_AMT,300 GRoss_Amt,4 Week_no, 12 Gross_qty,1000 dm_adj_total from dual
      UNion all
      select 1 month_no ,'wk2' week,120 DM_AMT,300 GRoss_Amt,4 Week_no, 12 Gross_qty,1000 dm_adj_total from dual
      union all
      select 1 month_no ,'wk3' week,120 DM_AMT,300 GRoss_Amt,4 Week_no, 12 Gross_qty,1000 dm_adj_total from dual
      union all
      select 1 month_no ,'wk4' week,120 DM_AMT,300 GRoss_Amt,4 Week_no, 12 Gross_qty,1000 dm_adj_total from dual
      union all
      select 2 month_no ,'wk5' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
      UNion all
      select 2 month_no ,'wk6' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
      union all
      select 2 month_no ,'wk7' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
      UNion all
      select 2 month_no ,'wk8' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
      UNion all
      select 2 month_no ,'wk9' week,200 DM_AMT,400 GRoss_Amt,5 Week_no, 20 Gross_qty,1000 dm_adj_total from dual
    So the data in Grid  will be like this
    month_no
    week
    DM_AMT
    GRoss_Amt
    Week_no
    Gross_qty
    dm_adj_total
    DM_ADJ_Final
    1
    wk1
    120
    300
    4
    12
    1000
    1000 * 300 /(300+400) = 428.57
    =1
    wk2
    120
    300
    4
    12
    1000
    1000 * 300 /(300+400) = 428.57
    1
    wk3
    120
    300
    4
    12
    1000
    1000 * 300 /(300+400) = 428.57
    1
    wk4
    120
    300
    4
    12
    1000
    1000 * 300 /(300+400) = 428.57
    2
    wk5
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    2
    wk6
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    2
    wk7
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    2
    wk8
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    2
    wk9
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    I need to calculate DM_ADJ_Final  where calculation for DM_ADJ_Final  will be like
                        = dm_adj_total * gross_amt/ (gross_amt (where month_no =1 ) + gross_amt (where month_no =2 )) ( Please refer  DM_ADJ_Final column above  for calculation with value )

    You apparently have (or intend) an association between rows where month_no = 1 and month_no = 2.
    But what is that relationship?  Is the month 2 row always 4 weeks later than the month 1 row?
    That relationship needs to be spelled out exactly.
    month_no
    week
    DM_AMT
    GRoss_Amt
    Week_no
    Gross_qty
    dm_adj_total
    DM_ADJ_Final
    1
    wk1
    120
    300
    4
    12
    1000
    1000 * 300 /(300+400) = 428.57
    =1
    wk2
    120
    300
    4
    12
    1000
    1000 * 300 /(300+400) = 428.57
    1
    wk3
    120
    300
    4
    12
    1000
    1000 * 300 /(300+400) = 428.57
    1
    wk4
    120
    300
    4
    12
    1000
    1000 * 300 /(300+400) = 428.57
    2
    wk5
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    2
    wk6
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    2
    wk7
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    2
    wk8
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    2
    wk9
    200
    400
    5
    20
    1000
    1000 * 400 /(300+400) = 571.42
    I need to calculate DM_ADJ_Final  where calculation for DM_ADJ_Final  will be like
                        = dm_adj_total * gross_amt/ (gross_amt (where month_no =1 ) + gross_amt (where month_no =2 )) ( Please refer  DM_ADJ_Final column above  for calculation with value )

  • Physician/Researcher needs help with this query

    Folks,
    Thank you in advance for looking at my problem. You are helping to save lives and make this world a better place.
    I am trying to find out the earliest date patients took steroid. I have:
    select patientid, visitnumber, steroid_start_date from treatments where steroid_start_date is not null and trim(steroid_start_date) != '/'
    order by patientid, substr(steroid_start_date, -4)
    I then have:
    patientid visitnumber steroid_start_date(this is a string column, not date or time, and it has so many junk in it, like /2003 , /)
    4 3 03/2004
    4 2 01/01/2005
    10 2 08/01/2005
    10 1 05/01/2002
    What I need is:
    4 3 03/2004
    10 1 05/01/2002
    I am not good with group by... having.... max.... How can I limit to one patient per row and this row is their earliest visit?
    Thank you very much in advance. You are helping to save lives.

    Here it is ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.53
    satyaki>
    satyaki>
    satyaki>with t
      2  as
      3    (
      4       select 4 patientid, 3 visitnumber, '03/2004' steroid_start_date from dual
      5       union all
      6       select 4, 2, '01/01/2005' from dual
      7       union all
      8       select 10, 2, '08/01/2005' from dual
      9       union all
    10       select 10, 1, '05/01/2002' from dual
    11    )
    12  select patientid,
    13         visitnumber,
    14         steroid_start_date
    15  from (
    16         select k.*,
    17                row_number() over(partition by patientid order by to_date(substr(steroid_start_date,-4),'YYYY')) rn
    18         from t k
    19         order by patientid
    20       )
    21  where rn=1;
    PATIENTID VISITNUMBER STEROID_ST
             4           3 03/2004
            10           1 05/01/2002
    Elapsed: 00:00:00.11
    satyaki>Regards.
    Satyaki De.

Maybe you are looking for

  • New ipod touch won't appear in my itunes or on my computer

    I got an ipod touch for christmas and it just will not show up under devices when i plug it into my itunes. it wouldnt activate at all, so then i used my brother's laptop. it finally activated but asked to be "restored to factory settings" first. my

  • Firefox stops responding and crashes

    My tablet is an Asus tf300t with an Android 4.02 OS. I really like what Firefox has to offer, but it is not working for me. I am even writing this on Chrome because Firefox would stop responding constantly.

  • Print Preview / output

    Hi Gurus I need to see the print preview or print output of an document like Sales invoice or Outbound delivery in Languages- Sweden , Italy , Spain,France. I have tried by setting in the respective language in VL02N but still reflecting the print pr

  • ADF Styling Problem,

    Hello everybody , i have a problem styling an ADF Application , i followed this example http://technology.amis.nl/blog/5722/using-adf-faces-11g-skinning-for-setting-the-styles-of-specific-component-instances-or-groups-of-instances and i created the f

  • Zif/fpc 30 pin connector & 2.0 pitch SMD connector 4 pin

    Hello... I'm working on a project which would incorporate a few connectors which I haven't found in the database; 2.0 pitch connector 4 pin (shown as 6 pin in the pdf, but it should really be 4 pins) http://www.buy-display.com/download/connector/ER-C