Get total number of filled row in table in SQLite - iphone

My Question is Similar to MySQL, count the number of "filled" fields in a table
But i can not got my proper solution. How is it possible in Sqlite?
I Know about get using for loop. but i want to get by query.
Please help me on this issue.
Thanks in Advance.

A query like this will work:
SELECT COUNT(*) from raw where rawData <> '' AND rawData IS NOT NULL
This assumes there is a table called "raw" and the column you're checking against is "rawData"

Related

How to save a query result into a column using postgresql

This may be a simple fix but Im somehow drawing a blank. I have this code below, and I want the results that I got from it to be added into their own column in an existing table. How would i go about doing this.
Select full_name, SUM(total) as sum_sales
FROM loyalty
where invoiceyear = 2013
GROUP BY full_name
order by sum_sales DESC;
This leaves me with one column with the name of employee and the second with their sales from that year.
How can i just take these results and add them into a column in addition to the table
Is it as simple as...
Alter table loyalty
Add column "2013 sales"
and then add in some sort of condition?
Any help would be greatly appreciated!
If i got your question right, you need to first alter the table allowing the new field to be null (you can change it later on) then you could use an insert clause to store the value permanently.

Why UNION SELECT gives you the number of columns in SQLI

I am trying to figure out why one can figure out the number of columns from using 'union SELECT'
For example, if you have a webpage http://www.vulnerable-site.com/index.php?firstArg=1
I learned that you can put
http://www.vulnerable-site.com/index.php?firstArg=1 union SELECT 1,2,3,4 --
to find out the number of columns in the table. Basically, you keep adding numbers to till you stop getting errors. Why is that?
Can anyone please help me with this basic question.
Thanks
I came to know that the number of columns on both sides of the UNION statement must match. So, this command can be used to find out the number of columns in a table.
UNION keyword can be used to retrieve data from other tables within the database. This results in an SQL injection UNION attack. so Determining the number of columns required in an SQL injection UNION attack. there are two effective methods to determine how many columns are being returned from the original query. "ORDER BY" and "UNION SELECT"

Wrong display of count(*) result with PgAdmin and postgresql 9.3

I'm a little confused with my data, postgres returns wrong value with a simple count(*)
I use a :
select count(*) from DimUsers
it returns : 74280
this one :
select count(*) from DimUsers group by user_type
Returns :
72134,12288, 89850
this one :
select * from DimUser
displays a table of 1674280 rows
And my full database is estimated by pgadmin to 1674280 rows.
I can't see what is wrong with it, this happened to anyone before?
I recently encountered a similar problem. However I found that pgAdmin 3 was in fact returning the correct count value, except the column size for the count column was not auto-sized correctly to fit the data and thus it seemed like it was only returning the last 5 digits of the count. Increasing the size of the count column by using the column resize on the header row allows you to see the full number, but unfortunately you have to do this for every query you run.
As noted by rachekalmir the issue is pgAdmin 3. You can overcome this by giving "count" a longer column name. then you will see the full number.
select count(*) as mybiggggcount from DimUsers

Store the whole query result in variable using postgresql Stored procedure

I'm trying to get the whole result of a query into a variable, so I can loop through it and make inserts.
I don't know if it's possible.
I'm new to postgre and procedures, any help will be very welcome.
Something like:
declare result (I don't know what kind of data type I should use to get a query);
select into result label, number, desc from data
Thanks in advance!
I think you have to read PostgreSQL documentation about cursors.
But if you want just insert data from one table to another, you can do:
insert into data2 (label, number, desc)
select label, number, desc
from data
if you want to "save" data from query, you also can use temporary table, which you can create by usual create table or create table as:
create temporary table temp_data as
(
select label, number, desc
from data
)
see documentation

Number of rows returned in a sqlite statement

Is there any easy way to get the number of rows returned by a sqlite statement? I don't want to have to go through the process of doing a COUNT() first. Thanks.
On each call to sqlite_step, increment a variable by 1.
If you want the row count in advance, then there's no easy way.
To count all entries in a table, you can use the following SQL statement:
SELECT COUNT(*) FROM "mytable" where something=42;
Or just the following to get all entries:
SELECT COUNT(*) FROM "mytable";
In case you have already done the query, and just want the number of entries returned you can use sqlite3_data_count() and sqlite3_column_count() depending on what you want to count.