County of SQL based on the length

SELECT LENGTH(site_id),
  COUNT(site_id)
FROM site_data
GROUP BY LENGTH(site_id)
Results:
1 12
1 of 3
6-11209
7 17519
* (null) 0 *.

I wrote the query above to get the number of a column based on its length. But the problem is that the table has a lot of values null, which is not showing in the results.

Is there something fundamentally wrong with the query? Please help me.

Thank you.

Guru wrote:

SELECT LENGTH(site_id),
COUNT(site_id)
FROM site_data
GROUP BY LENGTH(site_id)

Results:
1 12
1 of 3
6-11209
7 17519
* (null) 0 *.

I wrote the query above to get the number of a column based on its length. But the problem is that the table has a lot of values null, which is not showing in the results.

Is there something fundamentally wrong with the query? Please help me.

Thank you.

COUNT as defined ONLY charges the non-null instances.

If you want a count, you want to use COUNT (*) in place of COUNT (site_id);

Tags: Database

Similar Questions

  • The data return based on the length

    How can we display data lines based on the length?

    Published by: 863765 on July 9, 2011 17:51

    863765 wrote:
    display data based on the length as given

    Select the table where length between merchantname? and?

    SELECT MERCHANTNAME COMPANIES WHERE LENGTH (MERCHANTNAME) BETWEEN 5 AND 10

  • createTextField setting width based on the length of the string

    I wonder if there is a way to easily calculate how wide to make a textfield you create dynamically with createTextField based on the length of a string that is passed as an argument. In other words, if you know you are going to use the font size, is there a way to know how many pixels you need? Thanks in advance to anyone who can offer assistance.

    have you looked into "TextField.autoSize?

    SPGAnne wrote:
    > I wonder if there is a way to easily calculate how wide to make a textfield
    > you create dynamically with createTextField based on the length of a
    > string passed as an argument. In other words, if you know the police
    > size you plan to use, is there a way to know how many pixels you need?
    > Thanks in advance to anyone who can offer assistance.
    >

  • Where conditional Clause based on the length of the field

    Hello people,
    I tried to search for this scenario in OTN and not been able to find any success so I will post the question here.

    I have two tables - with the detail records and the other being a table of codes. I need to join these two tables based on the code and the length of the code. Let me explain using examples.

    Scripts for creating the table and inserts
    create table ILLNESS_CODES(illness_code varchar2(4), illness_description varchar2(100));
    create table PATIENT_TB(patient_id varchar2(4), primary_cause varchar2(4));
    
    insert into illness_codes values('B10', 'Flu');
    insert into illness_codes values('B30', 'Hepatitis');
    insert into illness_codes values('B301', 'Hepatitis A');
    insert into illness_codes values('B302', 'Hepatitis B');
    insert into illness_codes values('B303', 'Hepatitis C');
    
    insert into patient_tb values ('1001', 'B101');
    insert into patient_tb values ('1002', 'B102');
    insert into patient_tb values ('1003', 'B30');
    insert into patient_tb values ('1004', 'B301');
    insert into patient_tb values ('1005', 'B302');
    insert into patient_tb values ('1006', 'B302');
    insert into patient_tb values ('1007', 'B303');
    insert into patient_tb values ('1008', 'B30');
    As you can see that patients * 1001 * and * 1002 * have no codes in the Master table. In this case, I want only the first 3 characters of the ILLNESS_CODES table.
    However, for B30, it has a Code and the same for B301, B302 B303 where I would meet the description based on the exact code.

    Example of output
    Patient ID   Illness Description
    =====================================
    1001         Flu
    1002         Flu
    1003         Hepatitis
    1004         Hepatitis A
    1005         Hepatitis B
    1006         Hepatitis B
    1007         Hepatitis C
    1008         Hepatitis
    Thanks in advance!
    SELECT p.*,
           NVL ( (SELECT illness_description
                    FROM ILLNESS_CODES I
                   WHERE i.illness_code = p.primary_cause),
                (SELECT illness_description
                   FROM ILLNESS_CODES I
                  WHERE i.illness_code = SUBSTR (p.primary_cause, 1, 3)))
      FROM PATIENT_TB p;
    
  • How to divide the resultset SQL based on the data in the form of scenarios?

    Hello

    I need to develop a query that should be divided into scenarios

    Ex:

    Scenario 1: If a product is sold to the United States and charged in the United Kingdom
    Scenario 2: If a product is sold to the United Kingdom and charged in the United States
    Scenario 3: If a product is sold and invoiced to the United States
    Scenario 4: If a product is sold and invoiced to the United Kingdom

    Based on 1 how to divide and provide SQL result to users based on the scenarios?

    Ex: Result should show all the data, saying that the result set is in scenario 1, etc..,.

    Please advice

    Thank you
    user12048986

    Hello

    You can use an expression BOX to classify each line:

    CASE  sold_country || ' ' || billed_country
         WHEN  'US UK'     THEN  1
         WHEN  'UK US'     THEN  2
         WHEN  'US US'     THEN  3
         WHEN  'UK UK'     THEN  4
    END     AS scenario_num
    

    If sold_country or billed_country is anything except 'UK' or 'US', then the above expression returns null.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.

  • Result of the query restriction based on the length of the field

    Hello

    I want to restrict the output of the query according to the length of a field (in fact, the length of the contents of a field).
    Ex: only those records where the length of the data in a field is more than 20 characters.

    Is it possible, can you give some advice on this subject...

    Thank you

    Hello

    Example:

    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    
    SQL> select to_date('16/8/2009 11:21:46','DD/MM/YYYY HH24:MI:SS') from dual;
    
    TO_DATE('16/8/200911:21:46','D
    ------------------------------
    16/08/2009 11:21:46
    
    SQL> select first_name from employees where length(first_name) > 20;
    
    FIRST_NAME
    --------------------
    
    SQL> select first_name from employees where length(first_name) > 10;
    
    FIRST_NAME
    --------------------
    Christopher
    Jose Manuel
    
    SQL> 
    

    Kind regards

  • divide characters based on the length

    How can I split string such as 'HELLO' => 'H' 'E' 'L' "L", "O" using the length

    OATTelecom wrote:

    How can I split string such as 'HELLO' => 'H' 'E' 'L' "L", "O" using the length

    Yes Type cast!

  • decode SQL based on the combination of codes

    create the sample table (number patient_id, location number)


    TOGETHER TO DEFINE
    Insert in the EXAMPLE
    (PATIENT_ID, LOCATION)
    Values
    (103, 10);
    Insert in the EXAMPLE
    (PATIENT_ID, LOCATION)
    Values
    (102, 12);
    Insert in the EXAMPLE
    (PATIENT_ID, LOCATION)
    Values
    (101, 2);
    Insert in the EXAMPLE
    (PATIENT_ID, LOCATION)
    Values
    (100, 5);
    COMMIT;


    Select * example

    PATIENT_ID LOCATION

    100                     5
    101                     2
    102                     12
    103                     10

    Codes:

    0 - NO
    1 RLO
    2 OLA
    4 RC
    8 LC


    My output should show:

    must divide the location based on the above codes and decoding.
    I have suggested to use the bitwise operators but could not work.

    Any help is very appreciated

    PATIENT_ID LOCATION RLO RC LC OLA

    100                      5                      Y           N           Y           N
    101                      2                      N           Y           N           N
    102                      12                    N           N           Y           Y
    103                      10                    N           Y           N           Y

    Hello

    Thanks for posting the instructions CREATE TABLE and INSERRT; It's very useful!

    You can use built-in BITAND function to do this:

    SELECT patient_id

    , CASE WHEN BITAND (location 1) <> 0 THEN 'Y' ELSE ' not AS END rlo

    , CASE WHEN BITAND (location 2) <> 0 THEN 'Y' ELSE ' not AS END OLA

    , CASE WHEN BITAND (location, 4) <> 0 THEN 'Y' ELSE ' not AS END rc

    , CASE WHEN BITAND (location, 8) <> 0 THEN 'Y' ELSE ' not AS END lc

    Example

    ORDER BY patient_id

    ;

    Relational databases work best when each column of each row stores 1 piece of information.  It is so basic to the design of database he called first normal form.  Think very carefully if you really want to store data in a standardized form like that.  A better design would be to have a separate for the location information table, where each line has indicated that a specific patient in a specific place, with no column by itself is unique.

  • TABLE OF UPDATE SQL BASED ON THE VALUE OF THE TABLE HELP

    Here is an example of a table that I have and I need basically help make and update statement. My syntax is all messed up. I have update the 'INDY' column WHEN THE NUM AND NUM 2 and INDY are the same. In other words it since it needs to update the last N with a 'Y '.
    TABLE NAME TEST_1
    
    NUM  NUM2     INDI
    1       A           Y
    1       A           Y
    1       A            N
    I hope this feeling...

    Here's what I have so far but it dosent seem to work... someone can point me in the right direction.



    UPDATE T_TEST
        SET INDI = 'Y'
        WHERE NUM IN (SELECT COUNT(NUM) FROM T_TEST WHERE INDI = 'Y' 
         GROUP BY NUM
        HAVING COUNT(NUM) > 1);
    UPDATE T_TEST T1
      SET INDI = CASE (SELECT COUNT(*) FROM T_TEST T2 WHERE T2.NUM = T1.NUM AND T2.NUM2 = T1.NUM2)
                   WHEN 1 THEN 'N'
                   ELSE 'Y'
                 END
    /
    
    3 rows updated.
    
    SQL> SELECT  *
      2    FROM  T_TEST
      3  /
    
           NUM N I
    ---------- - -
             1 A Y
             1 A Y
             1 A Y
    
    SQL> 
    

    SY.

  • I would like to know if it is possible to automatically adjust the length of a field in a form, ACROBAT PRO. which means that if I type a long word in this area 1, the 2nd field would not until now.

    2016-06-01 10-04-11.png

    No, it's not really possible. You can try to move the 2nd field based on the length of the field by using a script, but there will be speculation, at best.

  • Increase the length of the column - restriction key foreign vs MS SQL

    Hello

    I need to increase the length of the column (nvarchar) in some tables. Between these tables are foreign keys.

    When I try to do it on MS SQL databases using the command as "ALTER TABLE TABLE_NAME ALTER COLUMN column NAME NVARCHAR (50) NULL" then I get the error like below:

    Column ' dbo. TABLEA. NAME ' is not the same length or scale as the referencing column or the 'FKNAME' object depends on the column 'name'.

    Therefore resume, on MS SQL I drop all constraints, alter table and re-create constraints.

    When I do this same thing on the oracle database (oracle database a same pattern as MS SQL database, same fk, same tables, columns, etc.) using the command as "ALTER TABLE table_name MODIFY COLUMN NVARCHAR2 (40);  " then length is change without any erros and I wounder t - it a correct situation on oracle? -all the constraints are enabled. Oracle checks the length of data to foreign key columns?

    As I understand the error (ORA-02267: column type incompatible with the type of the referenced column) is the show that if the data type name is not equal between data tables not type length (?)

    To reproduce:

    1 create tables

    CREATE TABLE "TABLEA".

    (ACTIVATE THE 'NAME' NVARCHAR2 (20) NOT NULL,)

    NUMBER OF "TEXTID",.

    'PK_TABLEA' CONSTRAINT PRIMARY KEY ("NAME")

    );

    CREATE TABLE 'TABLEB.

    (SELECT 'ID' NUMBER NOT NULL,)

    NVARCHAR2 (10) "NAME."

    NUMBER OF "WWW."

    "TABLEB' ('ID') PRIMARY KEY CONSTRAINT

    );

    2. create the fk

    ALTER TABLE TABLEB ADD CONSTRAINT FK_TABLEB FOREIGN KEY ('NAME') REFERENCES 'TABLEA' ('NAME');

    On MS SQL, you get an error message on the same length of column ;) no

    Thank you

    Best regards

    Mateusz

    Whatever it is, the answer seems to be here: https://docs.oracle.com/cd/E17952_01/refman-5.5-en/create-table-foreign-keys.html

    "Corresponding columns in the foreign key and the referenced key must have similar data types. The size and the sign of the integer types must be the same. The length of the string types are not necessarily the same. For the non-binary (character) string, the character set and collation columns must be the same. "

  • Query SQL to split the lines based on the amount

    I have the data in the following format in the table.

    ORDER_ID PRODUCT_ID QUANTITY

    O1 A1   3

    I need to write the sql query to divide the data in following format:

    ORDER_ID PRODUCT_ID QUANTITY

    O1 A1   1

    O1 A1   1

    O1 A1   1

    Query must split the data based on the value in the quantity column.

    Thank you

    Developer

    Hello

    create table order_items (
      order_id varchar2(2),
      product_id varchar2(2),
      quantity number
    )
    ;
    insert into order_items values ('O1', 'A1', 3)
    ;
    -- Recursive Subquery Factoring
    with item(order_id, product_id, quantity) as (
      select
        order_id, product_id, quantity
      from order_items
      union all
      select
        order_id, product_id, quantity - 1
      from item
      where quantity > 1
    )
    select
      order_id, product_id, 1 quantity
    from item
    order by order_id
    ;
    drop table order_items purge
    ;
    
    Table ORDER_ITEMS created.
    
    1 row inserted.
    
    OR PR   QUANTITY
    -- -- ----------
    O1 A1          1
    O1 A1          1
    O1 A1          1
    
    Table ORDER_ITEMS dropped.
    
  • SQL script to insert values into a table based on the type of user

    Hello

    I have a requirement where I need to insert (username, groupname) in a table based on the user name.

    We have two types of user accounts:

    (1) user name, which starts with "DV" example: "DVPATM."

    regular user 2) example: 'PATM '.

    If the user name begins with "DV" under instruction insert should kick in

    insert into < tablename > (username, groupname) VALUES (< username > ' < groupname1 >).

    otherwise below insert statement should kick in

    insert into < tablename > (username, groupname) VALUES (< username > ' < groupname2 >).

    I need to use SQL or stored only procedure.

    Please suggest

    Thanks in advance

    All things being constant, you could use decode/case just for groupname by examining the first character t the user name, for example

    insert into (username, groupname) VALUES (, (substr ( , 1, 2) the case when "DV" then else end));

    Fixed edit: value for OTHERS, as noted by Frank

  • Eliminate the duplicate based on the condtion in Select of SQL query.

    Hi all

    I write the SQL query where I have to select values based on the condition in the column.

    Lets say I have 3 columns position, description, used, there are different values in the position but for some positions of the column description of the lines is the same and if column Description is the same and employee is null then that there should be only one row returned and if the description is the same but the employee column is not null then it should be several lines.

    I can't use Group by that we have around 35 columns in the select query.

    Please suggest any Solution.

    Hi Michael,

    I adds a column to the t2 to get the good understanding of my needs.

    Level
    Employee From Date to_date
    1 Test2 21.03.2014 21.04.2014
    2 Test4 21.02.2014 20.03.2014
    2 Test1 21.03.2014 21.04.2014
    2 Test3 21.04.2014
    3 MgrTest 21.03.2014

    Now, the result should look like this.

    Level
    Employee From Date TO Date
    1 Test2 21.03.2014 21.04.2014
    2 Test3 21.04.2014
    2 Test1 21.03.2014 21.04.2014
    3 Mgrtes 21.03.2014
    4

    There was an addition more as if this day is not null for the given level, then the query must return a single line of balnk more with the same position, I am reached using any Union and works very well I'm stuck with the point above.

  • SQL that are based on the values of the corresponding fields.

    Hi my name is Hawk.

    I'm new to the Forum, and I wanted to just introduce myself and say hi.

    I have a daunting task to summarize values and filling in a spreadsheet with columns. I have 600 lines to go, and I was wondering if

    someone knows a way in sql to sum (a body of numbers) based on the existence of a value being the same on another field of varchar2.

    For example, here is an example of the data table that I have.

    CREATE TABLE EXAMPLE

    ("FIRSTNAME", VARCHAR2 (20 BYTE),

    VARCHAR2 (20 BYTE) "LASTNAME."

    NUMBER OF "SUMVALUE."

    NUMBER OF "ROW_ID".

    );

    Insert into SAMPLE (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) values ('Charlie', 'chocolate factory', 100, 1);

    Insert into SAMPLE values (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) ('Johnny', 'Desire', 200, 2);

    Insert into SAMPLE (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) values ('P', 'Frankenstein', 300, 3);

    Insert into SAMPLE (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) values ("Charlie", "chocolate factory", 400, 4);

    Insert into SAMPLE (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) values ("Charlie", "chocolate factory", 500, 5);

    and Yes, I have 600 lines having to ask and things to the top score on manually, it's just bs data...

    So what I do is the following.

    Write some sql that will total the number field (sumvalue) based on data with firstname = lastname = chocolate factory and Charlie.

    It seems so simple, but still I can not understand how do.

    Is that what I'm trying to make sense?  Also, I hope this is the right place to post this. I looked on this before I posted to make sure.

    Hawk.

    Hi, Hawk,

    Here's one way:

    SELECT SUM (sumvalue) AS total_sumvalue

    SAMPLE

    WHERE firstname = 'Charlie '.

    AND lastname = 'chocolate factory '.

    ;

    Welcome to the forum!

    There are those who use the forum for years and have not yet learned to post CREATES instructions TABLE and INSERT for their sample data, as you did.  Keep up the good work!

    You should also post the exact results you want from the data provided.  For example

    TOTAL_SUMVALUE

    --------------

    1000

    (this is what produces the query I posted).  As you can see, without that David and I came with 2 different interpretations of what you want and maybe aren't exactly what you need.

Maybe you are looking for

  • An easy way to re-import massive media after a hard disk crash if the library files are intact?

    Hello I'm running 10.2.3 on OS X 10.11.3 FCPX. My external hard drive just crashed, and while I was able to save most everything else (including library files, proxy support, etc.), Miss me about 90% of the media about 2 000 "original" files. Because

  • PROBLEM WITH THE INSTALLATION OF UPDATES

    When the computer tells me to reboot to complete the installation of updates, I do.  It stops normally, but when he tries to restart, the screen goes completely dark.  I have to press the market / stop button for 4 seconds & it stops.  I wait a few m

  • to repair without losing data

    Hi, I have a problem with the laptop.it sometimes get crashed.i have vista.how can I fix it without losing anything, programs and documents? can I use vista dvd running vista to repair without losing anything? Please answer me...

  • Associated account manager SmartNet contract to know

    Hello world I'm new to SmartNet contracts, I came to know that each SmartNet contract is associated with an account manager. How can I find the details of the account manager. Who should I contact. Kind regards ABY Laurance claudon

  • How to use memory and boost system performance by using 8 gb win7 Professional 64-bit

    Hello I m using HP430 (I have 3 Basic) laptop with win7 64 bit Professional installed. recently, I ve upgraded to 8 GB of ram, but I don't really see the system performance problem. Can anyone guide the optimal memory use and improve the performance