sqlite - replacing existing rows in particular range with data from another table - ios

I have table with 1500 rows and nearly 10 columns ..
I have imported new data from csv file into another new table, now I want to copy data from this new table to already existing table's 10th column ..
when I try
insert into presentDB (column10) select column1 from importDB
its inserting another 1500 new rows ..
UPDATE presentDB SET column10 = importDB.column1
this thing is throwing an error ..
UPDATE presentDB SET column10 = (SELECT column1 FROM importDB WHERE rowid between 1 and 1500)
gets executed, but copies the first value in column1.importDB to all the cells in present db.
also what will be the query for
copying data in particular range like 100 to 200 from importDB to 500 to 600 in presentDB
can anyone please show a proper direction :) thanks, any help is appreciated :)

You need to have some column that identifies records.
If you have that, you can use a correlated subquery:
UPDATE presentTab
SET column10 = (SELECT column1
FROM importTab
WHERE importTab.ID = presentTab.ID)

Related

How do I filter a large dataset in Google Sheets without getting duplicates returned?

I am trying to create a new worksheet in a Google Sheets doc where I need to filter a Master data set based on values in a specific column.
I originally did a VLOOKUP in each specific column that I wanted returned but it brough back blank rows for the corresponding rows that did not match, and eventually it broke for some reason and stopped returning the correct data.
I have been trying to find a new way to do it and have most recently been trying XLOOKUP, but it returns duplicate rows of each correct match.
The original datasheet is mostly populated itself by VLOOKUPS, drawing in information from other trackers so I feel this must be why it is falling over.
The dataset looks roughly like this:
ID
Y/N
Last Name
First Name
col
col1
col2
etc
1
Y
SMITH
A
Cell 1
Cell 2
Cell 1
Cell 2
2
N
JONES
B
Cell 1
Cell 2
Cell 1
Cell 2
There are 40+columns in the tracker but I basically want to have a new sheet where I filter and return only the 'Y' values in the Y/N column, and return columns A:N (including the ID column) without leaving blank rows between the matches, and without returning dupllicates.
I have tried everything I can think of but I just cannot make it work, so any help on the matter would be GREATLY appreciated.
Thanks for reading.
try:
=FILTER(Sheet1!A:N; Sheet1!B:B="Y")
You can also try along with player0 answer, if you want also to import the headers:
=Query(Sheet1!A:N,"Select * Where B = 'Y'"),TRUE)

Copying data from every nth column to a new column

i have a sheet with data in i4,i11,i18,i25 etc; besides this data in every 7th cell of column i starting at i4 all the other cells in i column are blank(there is data in other columns i.e."a-h") I would like to copy the data from these cells in column i starting at i4 then every 7th cell in a new column n that has the data starting in n2. I have tried an example I found here with a list of names with to solutions and can't get either to work.
=filter(I4:I, mod(row(I4:I)+1,7)=0)
=offset(I$4,7*(row()-1)-2,)
Thank you!
=QUERY(I4:I,"select * skipping 7")
The following should also work for your case
=QUERY(I2:I,"select * where I is not null")
it should be:
=FILTER(I4:I, MOD(ROW(I4:I)+3, 7)=0)

Excel to remove duplicates (like a SELECT ID, max(Monday), max(Tuesday)

I've got a csv from a 3rd party that is imported into Excel that I cannot figure out how take the data that looks like this so that each row is collapsed down and the blanks are gone. In SQL I would just do a select on the fields I want and de-dupe those, then max on the others to get rid of the blanks. How would this be done in Excel?
Data:
Expected results:
Assumption:
1. you only need to do this once
2. Your source data starts at A1 (the headers)
3. The list of IDs are sorted and with fixed number of rows for each ID (6 rows in your example) .
Steps:
Create a new worksheet
Fill column B with the list of unique ID (in the same order as your data), start with B1
Fill column A with a serial number: 0,1,2,3,4.... up to the number of unique IDs, start with A1
Fill in column C the following formula
=TEXTJOIN("|",TRUE,OFFSET([src worksheet]!$B$2:$O$7,A1*4,0))
Then you should be able to use "TextToColumn" function to make the table you want.

Printing sheets of labels in SSRS 2008 based on data in a table and specific quantities per label

I need to come up with a form in SSRS 2008 that prints labels based on information stored in a table or tables. So far I have been unsuccessful in my online searching. How do I tell SSRS that I want the KitOrder.QuantityCommitted quantity of labels to print for each item? (each item has it's own quantity) I will likely be printing labels for 20-30 items at a time. In case it's helpful to know, there are 18 blank labels per sheet.
edited 10/01/15
Sorry, I played around with with the example you gave and wasn't able to get my report to work. I am not an expert with SSRS.
I have 2 tables I am using to get the info I need for the labels and only need the columns listed below the table names at this point.
KitOrder INNER JOIN Item
KitOrderNumber ItemNumber
Quantity ItemDescription
I am using KitOrderNumber from a dropdown box - IN(#KitOrderNumber) - as my Parameter. The ItemNumber and ItemDescription print on the label. Would there be some custom code I could use that would return 3 labels when KitOrder.Quantity = 3 instead of just 1 label?
Edited 10/05/15 - I was finally able to get my report to work as needed. Thanks so much for your help. The sqlfiddle was quite helpful to me.
I hate when people suggest this when it's not necessary but I think this is one of the times that you'll need to manipulate your data in SQL before the report.
I can't think of an easy way to do it with SSRS that doesn't involve a lot of code.
You create a temp table with your possible quantities then cross join your table to create a separate record for each product based on the number in your Quantity field.
;WITH Quantities AS (
SELECT 1 AS Num
UNION ALL
SELECT 1 + Num
FROM Quantities
WHERE Num <= 30
)
Select * from Products
CROSS JOIN Quantities
WHERE Num <= Quantity
This assumes that your data is in a table called Products.
If you have a query, you can SELECT your fields INTO a #Temp table and use that in the Select statement.
For the report, you can set the Columns peoperty on the Report to use as many columns as your label sheet has.
Here's an SQLFiddle I made that you can play with:
http://www.sqlfiddle.com/#!3/bb413/2

Fastest query for random row from subset of large table - postgresql

I am using rails and Postgresql. I have a very large table that includes a column called status. From this status column a lot of rows have a value of 1. I want to select a random row based on all rows with a value of 1 in the status column. Each row also has an id and they are sequential.
What is the fastest way to get this random row?
Try to use ActiveRecord solution, e.g :
Model_name.where(status: 1).limit(1).order("RANDOM()")
OR :
Model_name.where(status: 1).order("RANDOM()").first
Hope this helps.
You can play with OFFSET option
SELECT * FROM users WHERE status = 1 OFFSET random()*I LIMIT 1;
The I is the number of rows in table.

Resources