DB result Count in Group by results showing directly in Tableau - analytics

I am a newbie to Tableau, I am able to create graphs and analytics from raw data (required columns / fields queried with conditions).
But I feel instead of Tableau showing the count etc. by extracting the raw data,
Is there a way I can get count from DB directly grouped by other columns and represent it in Tableau.
E.g. suppose this is my DB table with raw data
COUNTRY USERTYPE USERNAME USERID
US PREPAID u1 u1
US PREPAID u2 u2
US POSTPAID u22 u22
IE PREPAID u4 u4
IE POSTPAID u5 u5
. . . .
. . . .
. . . .
and my count query is like
SELECT count(USERNAME), COUNTRY, USERTYPE
FROM USERSTABLE
WHERE USERNAME NOT NULL
GROUP BY COUNTRY, USERTYPE
Data to tableau is (query I run in tableau)
Country USERTYPE COUNT
US PREPAID 10
UK PREPAID 20
IN PREPAID 15
GB PREPAID 8
IE PREPAID 2
US POSTPAID 9
UK POSTPAID 5
IN POSTPAID 3
GB POSTPAID 6
IE POSTPAID 65
I want to use the counts instead of raw data processing in tableau.
Appreciate any tips or way to do this.
Why Am I doing this ?
This is a very huge table with millions of rows, I do not want all of these to be pulled to tableau server, ther eis no other analytics done. Instead just get the count running query directly in DB Server
Thanks!

You can create a custom SQL query that only fetches the data you want from the server.
Open Tableau
Connect to your DB
Choose a DB
Under your list of tables you have a "New Custom SQL" option
Insert your query
Run
With that you only feed - in your case - the count of usergroup/country into Tableau and none of the RAW data.
If that's a one off thing, that's no problem. If you want to give it to your (non-technical) users you might want to create a view in the DB instead and connect to that from Tableau or extract that query to save on Tableau Server.

Related

Multiple Manufacturers ID DB REPLACE - opencart 3.0.3.6

Can please someone help me with DATABASE code? SELECT * FROM oc_manufacturer WHERE 1
I have combined two opencart stores into 1, so I have now multiple manufacturers and different products are assigned to them from each store. Before I can delete the duplicates, I need to assign the right id to right products. So..
If manufacturer id is 11
And the same manufacturer is 57
How can I assign a right manufacturer to a products that have 57 id, but needs to be 11 now.
Can you send me the right code so I can run in SQL?
You can do it on your own risk. First make full backup of your DB
Next ran this query in SQL edit in phpMyadmin:
UPDATE `oc_product` SET manufacturer_id = 255 WHERE manufacturer_id = 5
Where in my example 255 is the new, or existing manufacturer_id which you need to assign to the product and 5 is the manufacturer_id which you later will delete/remove.

SSRS multiple datasets: How to display only records that are not in both Datasets

I'm using SSRS 2008 R2 and building a report with Report Builder 3.0.
I need to query 2 databases, a Central one here at headquarters and a Satellite one in Australia.
They both have a table called Buyers. The satellite site just contains a smaller set of data that we will return to central at a later date.
They have the following fields; idBuyer, IdCustomer, DateRegistered
Right now I want to query all the records in the Satellite site for Customers (idCustomer) that are not already in the same table in the central datasource
I’m using a LookUp using idBuyer to join the datasets in a Tablix. Now I just want to filter for results where idCustomer from the Satellite dataset is not in the Central Dataset
Any pointers would be appreciated as I assume this would be pretty simple but I’m not getting it to work
Ideally you should do this in SQL. It would make the report a lot quicker.
SELCT ID FROM SATELLITE WHERE ID NOT IN (SELECT ID FROM CENTRAL)
However, that's not always possible so you can filter the Satellite db where the ID is not in the CENTRAL ID using the InSTRing funtion.
For your filter, set the Expression to idBuyer
=IIF(INSTR("|" & Fields!idBuyer.Value & "|", "|" & JOIN(LookupSet(1, 1, Fields!idBuyer.Value, "CENTRAL"), "|") & "|"), 0, 1)
This will create a string of the IDs from CENTRAL db and look if the ID from the Sattelite DB is in it. If the ID is in the CENTRAL db, the row gets a 0 else 1. Then set the Value to 1.
The Pipes ( | ) is used to separate the values so it doesn't find 25 when you have 125 or 251 in the list.

MS Access Database Query help required

I have an access database with over 210k records. they are a list of product codes. with associated product codes. I want to create an access query that associates only one product code per line but merges the associated products into a single column matched to that product code but sepertaed by a , (comma)
Example of columns in access database
Product code: Associated product
100000 2548741
100000 4578214
100000 1254712
100000 5687412
100000 1469787
100000 9874582
100000 5478126
I want the following
Product code: Associated product
100000 2548741,4578214,1254712,5687412,1469787 ,9874582, 5478126
Thanks in advance.
This is how to do in vba: http://support.microsoft.com/kb/318642
Create a SQL query that retrieves the data that you want.
Use some client-side code to format the data the way you want.
SQL is used to manipulate (retrieve, add, remove, update) data, not to format it in a specific output format.

Social feed system design

http://twitter.com/#!/ladygaga
When ladygaga tweet 1 message, does it mean to insert 1 data record for EACH of her followers (total 12,221,751)? So totally 12,221,751 records are inserted?
Any clues in designing such a social feed system?
------------------------------- Edit line -------------------------------
Real issue:
Performing SELECT tweet FROM Tweets IN ([FollowingIDs]) is not possible in google app engine, which limiting to a maximum of 30 items in the IN clause
While in app engine it actually means, performing 30 queries in parallel, which is not very wise to do so I guess.
Even if I am allowed to overtake the 30 limits,
what if I am subscribing to 10000 people? I am not sure if there are any performance issues to do it in MYSQL or any other kind of database infrastructure using the "IN clause"
(the bigtable of app engine is different from MYSQL)
So it is better to use the IN clause to query?
or setting up a UserFeed table for storing the feed relationship?
or 3rd method?
Database/SQL guru please help
Please see this talk from Google I/O 2009 to see how to handle these sort of cases on App Engine with a 'fan out' data structure.
Can you imagine it?
no
every people has list of followers
ID | FOLLOWER__ID
ladygaga | genesis
ladygaga | user
//php
$result = mysql_query("SELECT ID FROM followers WHERE FOLLOWER__ID = 'genesis';");
while($row = mysql_fetch_assoc($result)){
$select[] = $row['ID'];
}
$tweets = mysql_query("SELECT * FROM tweets WHERE owner IN (".implode(",", $select).")");

Query a Lookup Table in Excel or Access

I've got a mental block about what I'm sure is a common scenario:
I have some data in a csv file that I need to do some very basic reporting from.
The data is essentially a table with Resources as column headings and People as row headings, the rest of the table consists of Y/N flag, "Y" if the person has access to the resource, "N" if they don't. Both the resources and the people have unique names.
Sample data:
Res1 Res2 Res3
Bob Y Y N
Tom N N N
Jim Y N Y
The table is too large to simply view it as whole in Excel(say 300 resources and 600 people), so I need a way to easily query and display (A simple list would be ok) what resources a person has access to, given the person's name.
The person that will need to use this has MS Office, and not much else on their PC.
So, the question is: What is the best way to manipulate this data to get the report I need? My gut says MS Access would be the best, but I can't figure out to automatically import data like this into a normal relational database. If not Access, perhaps there are some functions in Excel that could help me out?
You should normalize your data. This will make it easier to query against. For example:
table users:
UserID UserName
1 Bob
2 Tim
3 Jim
table resources:
ResourceID ResourceDesc
1 Printer #1
2 Fax Machine
3 Bowling Ball Wax
table users_resources:
LinkID UserID ResourceID
1 1 1
2 1 2
3 3 1
4 3 3
SELECT ResourceID
FROM users_resources, users
WHERE users.UserName="Bob"

Resources