Product List Position in Google Analytics Event Table - sql

I want to analyze the Product List Position in Google Analytics Event Table. However, during the installation, our Technical Team made a mistake in product list position. Some items' position starts from 0. How to fix this problem with sql? I want to fix only the starting 0 position's list.
Best.

Not sure if I fully understand your issue, but you might insert data to the table and then remove specified rows with 0.
For example:
insert into 'project-name.dataset.table' (select col1, (items.coupom, items.affiliation, items.refund) from 'project-name.dataset.table' where items.refund is null );
It will looks like below:
And then delete unneeded rows
delete from 'project-name.dataset.table' where items.refund is null;
Result will be like below:
Please note that this may process a lot of data and you will have to insert the missing data in the last field that was affected by the error.

Related

count how many time an item has been used, and reset that number

need some help please...
my problem is, there are some items lets say a1,a2,a,3 - b1,b2,b3 - c1,c2,c3 which after certain uses (4) need to be cleansed to be used again.
i want to keep some data about this process so i made the following table in SQL
CREATE table items
(
itemName varchar(10),
concept varchar(10)
)
itemName is self explanatory: a1,a2,a3 etc.
concept is either "Use" or lets say.. "Cleanse"
data example
INSERT INTO items (itemName, concept)
values
('a1','Use'),
('a2','Use'),
('c1','Use'),
('b3','Use'),
('c2','Use'),
('a1','Use'),
('a1','Use'),
('a1','Use'),
('c2','Use'),
('a1','Cleanse')
select COUNT(*) as count,itemname, concept from items group by concept, itemName
so every 4 insert of item "a1" with concept "Use" the next one has to be "Cleanse"
for now, i have been able to keep track of the process but, i've noticed some items being used more or less times than 4.
now, the problem is... i have no idea how make a counter limited to 4 and how to reset it after..
perhaps, it needs a table for only Use and another for Cleanse ??.
i though with a simple count(*) would be enough... i was so wrong.
perhaps i need a validation somewhere else ._. ugh im lost
oh and btw im using tkinter gui to enter this data
so.. please some enlightenment
i imagined with a count(*) query would work

Replacing Null Entries with a Zero

I've been working on learning SQL starting with basically no knowledge. I've only been at this for about a week.
I'm working with a piece of simulation software. I've been given a task to run many replications of a simulation that will generate random events of either something happens or nothing happens. The sim will create a table of the events and a column for replication numbers. If the event happened then it will get an event number, if it didn't, it will skip that rep and go to the next. I need a query to take the replications that have no event and replace the null entry with a zero.
As an added bonus, I might need to generate the number for the replication where there is a null.
The last bit of code I tried looked like this:
SELECT IsNull(table1.column1, 0)
FROM table1
SELECT COALESCE(table1.column1,0)
FROM table1
Should do the trick. COALESCE returns the first non-null value it finds, so this should work.

Update log table with data from the log table

Due to recent updates to the recent database, I have run into a weird problem. I have two tables, tVehicleDeal table and tVehicleLog table. We did a 'migration' meaning we created an app that will transfer the data from a old database to a more relational database. This process took awhile, but it finished and everything seemed good to go. What happens now, is that anytime tVehicleDeal is updated, the corresponding information is inserted into tVehicleLog. The problem that has occurred is.. I ran a script that would update the current deal in tVehicleDeal to the most recent log in tVehicleLog. I made an error in my script, and not all the current deals in tVehicleDeal were updated properly. As a result, when the users updated the active deal in tVehicleDeal, not all the information was inserted into the tVehicleLog. I need to find a way to update the newest entry with some fields from the past entries such as the date it was titled. Some Deals have as many as 20 different logs for it whereas some may have only 2 or 3. I have found this link here but I'm not 100 percent positive this is what I'm looking for. I have tried something similar to this but I am unable to get anything to work using the examples found on that page. Any other ideas will help greatly!
EDIT:
What I am unable to figure out is how to update a column in tVehicleLog. For example:
In the tVehicleLog table there are 6 results for a particular DealID.
The first through 4 do not have a titled date in it, but the 5th row does have a titled date.
I can't figure out how to update the titled column the 6th row for that dealID based on the 5th row that does have the titled date.
The link provided above looked like it was something I was looking for but I was unable to get that solution to work.
Based on this line from your question,
I can't figure out how to update the titled column the 6th row for
that dealID based on the 5th row that does have the titled date.
It seems like this should fix your problem. It is written only to solve this specific scenario. If other scenarios exist that are not exactly like this one, adjustments may have to be made. If I didn't understand your problem, please post further clarification.
UPDATE L1
SET TitleDate=L2.TitleDate
FROM tVehicleLog L1
INNER JOIN tVehicleLog L2
ON L1.DealID=L2.DealID
AND L2.TitleDate IS NOT NULL
WHERE L1.<PrimaryKeyColumn>=#ThePrimaryKeyColumnOfTheRowYouWantToUpdate

How to remove row that exists in another table?

I have two tables. Main table is "CompleteEmailListJuly11" and the second table is "CurrentCustomersEmailJuly11". I want to delete rows in CompleteEmailListJuly11 table that CurrentCustomersEmailJuly11 has based off email.
I've tried this following Delete example, but it doesn't do anything close to what I'm trying to do. This only shows me the ones that EXIST in the database, it doesn't show me the the list of emails that AREN'T matching.
DELETE * FROM CompleteEmailListJuly11 AS i
WHERE EXISTS (
SELECT 1 FROM CurrentCustomersEmailJuly11
WHERE CurrentCustomersEmailJuly11.email = i.EmailAddress
)
Help is greatly appreciated.
This is the query I think you need:
DELETE FROM CompleteEmailListJuly11
WHERE EmailAddress IN (SELECT email FROM CurrentCustomersEmailJuly11)
Ps: The DELETE query does not delete individual fields, only entire rows, so the * is not necessary, you will also need to "Execute" this query rather than "Previewing" or "Exporting"
If you're building your DELETE query in Access' query designer, notice there are two different modes of operation which seem similar to "go ahead and do this".
Datasheet View (represented by the grid icon labeled "View" on the "Design" section of the ribbon). That view enables you to preview the affected records, but does not actually delete them.
The "Run" icon (represented by a red exclamation point). "Run" will actually execute the query and delete the affected records.
If you already know this, my description may seem insulting. Sorry. However, it seems that folks new to Access can easily overlook the distinction between them.
You can use something like this adapted to delete
SELECT ... // complete
EXCEPT
SELECT ... // current
I am not sure exactly how it maps to delete but take a look at that.
I fond it in a similar question: How do I 'subtract' sql tables?
We can use Correlated Query to resolve the issue like
DELETE FROM COMPLETE C
WHERE EMAIL = (SELECT EMAIL FROM CURR CU WHERE CU.EMAIL=C.EMAIL);

SQLite issue with Table Names using numbers?

I'm developing an app which requires that the user selects a year formatted like this 1992-1993 from a spinner. The tablename is also named 1992-1993 and the idea is that using SQL the values from this table are pulled through with a statement like this select * from 1992-1993. When I run the emulator however, it throws an error.
If I then relabel the Spinner item to NinetyTwo and rename the table to NinetyTwo and run the emulator it runs as expected and the data is pulled through from the table.
Does SQLite have an issue with numbers in table names?
Yes and No. It has an issue with numbers at the beginning of a table name. 1992-1993 is an expression returning -1. Try to rename the table to Year1992.
Here a similar issue on SO.
sorry for late post
There may be a deeper issue here - is the structure you are using (table name per item in spinner) the best one for the job?
You may find that you want a number of tables e.g.
spinner_value (id, value)
form_data(id, spinner_value_id, etc ....)