Google Query - Generic column references for labeling - google-query-language

I'm building a quality assurance sheet which automatically pulls values from one tab, to a separate one, for each agent.
I'll need to write one per agent. To simply the process, would it be possible to reference the first column selected without specfiyng it by letter?
So GROUP BY and LABEL could be X where X so I only need to edit the select row.
Below is the current query I am using.
=QUERY('Bimonthly Report 2017'!A:AN,
"SELECT D, sum(F)/count(F), sum(L)/count(L)
WHERE F >0
GROUP BY D
LABEL D 'Category'"
, 2)

It's possible. Just input the data as a array literal.
=QUERY({'Bimonthly Report 2017'!A:AN}, "SELECT Col4, sum(Col6)/count(Col6), sum(Col12)/count(Col12) WHERE Col6 >0 GROUP BY Col4 LABEL Col4 'Category'" , 2)

Related

How to compare two unsorted tables in google spreadsheet

I'm trying to filter-in only the rows from table Today which were not in table Last time (The first two columns are the identifiers).
These were my failing tries:
=IFNA(QUERY(ArrayFormula(if(countif(V8:V30&" "&W8:W30,Q8:Q30&" "&R8:R30)=0,Q8,"")),"select Col1 where Col1 <> ''"), "")
Tried to add an = in the criterion field.
=IFNA(QUERY(ArrayFormula(if(countif(V8:V30&" "&W8:W30,"="&Q8:Q30&" "&R8:R30)=0,Q8,"")),"select Col1 where Col1 <> ''"), "")
Use this formula
=FILTER(A3:D, NOT(COUNTIF(F3:F, A3:A)))
FRESH is values in A NOT in F
Reference:
FILTER

SQL Union All alias from first table?

I have two tables
[data] - title,maker,partnum,price
[cross] - product(data.partnum),title,maker,partnum,price
What I want is listing all product via sysn number. How can I get with union all data like that with ordering ->
[data table] Microsoft, "some note", 9989, $20
[cross table] Microsoft reseller, "some note", 1045, $30
[cross table] Apple reseller in Microsoft :), "some note", 2233, $40
virtual spacer :)
[data table] Microsoft, "some note", 9989, $10
[cross table] Lenovo reseller in Microsoft..
Im trying with this
SELECT `title`,'Microsoft' AS `maker`,`partnum`,`price`
FROM data as d
WHERE sysn=%s
GROUP BY partnum
UNION ALL
SELECT `title`,`maker`,`partnum`,`price`
FROM cross as c
WHERE c.product=d.partnum
GROUP BY `partnum`
Thanks
It's not entirely clear what you are asking. Consider setting up an example schema and data in http://sqlfiddle.com.
A "virtual spacer" is going to be very messy to achieve. It's not totally impossible, just messy.
For returning rows in a particular sequence, you are going to need to add an ORDER BY clause.
It's not at all clear why you are including GROUP BY clauses. The GROUP BY on the first SELECT would effectively "collapse" example output rows 1. and 5. given the same value 9989 for partnum. Absent an explanation of why you need a GROUP BY, I'm going to guess that what you really intended was an ORDER BY clause.
It's also not clear why the literal value 'Microsoft' would need to appear in the SELECT list, in place of the maker column from the data table. There's nothing invalid SQL-wise with doing that. But absent an explanation, it just doesn't make much sense.
The question we should to ask... Why is this specific result needed? Is there a different result which would be easier to achieve, which would equally satisfy the requirements?
Setting aside the "virtual spacer" row, the return from a query like this seems like it satisfies most of the specification:
SELECT t.src
, t.title
, t.maker
, t.partnum
, t.price
FROM (
SELECT '[data]' AS `src`
, d1.title AS `title`
, d1.maker AS `maker`
, d1.partnum AS `partnum`
, d1.price AS `price`
, d1.partnum AS `product`
FROM data d1
WHERE d1.sysn = ?
UNION ALL
SELECT '[cross]'
, c2.title
, c2.maker
, c2.partnum
, c2.price
, c2.product
FROM cross c2
JOIN data d2
ON d2.partnum = c2.product
WHERE d2.sysn = ?
)
ORDER BY t.product DESC, t.src DESC, t.price ASC
If you are using MySQL, "cross" is a reserved word and you must enclose cross in backticks to use it as a table name (The backtick is next the the '1' on the keyboard on the upper left).

sql select to extract and link the record above

I need some assistance with my extract. Below is a view of my data and how it is extract from a MS SQL database.
My challenge is that the database does not differentiate from the different "email address" . How do I link email address record to the record above.
Secid|Name|Question|Answer|
2|load1|Name of Principle|Joe Make|
2|load1|Contact Number|12234423|
2|load1|Email address|joemake#mymail.com|
2|load1|Name of Principle|Amy Soup|
2|load1|Contact Number of Principle|23134|
2|load1|Email address|amysoup#mymail.com|
2|load1|Name of Teacher|james blue|
2|load1|Contact Number|8787878|
2|load1|Email Address|jamesblue#mymail.com|
2|load1|Name of Secretary|CHARLES black|
2|load1|Contact Number|989897|
2|load1|Email Address|chblack#mymail.com|
If you don't have any column to order by (e.g. a monotonically increasing identity column, or a timestamp), I'm afraid you're honestly out of luck. There is no way to guarantee any sort of ordering of the rows for any query.
What you can do, however, is export the data into an Excel sheet and then look at it manually and put the rows in the right order, assuming you can figure it out. Unfortunately this is really going to be the only way.
If you had a column you could order by, you can use a join to group the rows, assuming you had a way of identifying the start of each set - in your case a Question like 'Name of %' should probably work. Assuming an identity column called Id, something like:
select t.*, tGroupStart.Id as GroupId
from myTable t
join myTable tGroupStart on tGroupStart.Id <= t.Id
and tGroupStart.Question like 'Name of %'
where not exists (
select 1
from myTable t2
where t2.Id <= t.Id
and t2.Question like 'Name of %'
and t2.Id > tGroupStart.Id
)

How to cascade parameters in SSRS having specific values

I have 2 parameters 'Groupby1' and 'Groupby2' in my report,for the first parameters i have specified some values like Column A,column B,Column C. Now i need to make the 2nd parameter cascading based on the first one like if i select Column A in Groupby1 parameter it should display only Column B and Column C in Groupby2 parameter.Is this achievable?
Yes, it's easily achievable. The trick is to make a dataset dependent on just the first parameter, and use it's results for the available options of the second parameter.
A little more detail on how you'd make that happen:
Create the first parameter with options. (GroupBy1)
Create a dataset that uses that parameter either in Where or as a filter.
SELECT 'Web' as Department WHERE 'IT' in ( #GroupBy1 )
UNION ALL
SELECT 'Database' as Department WHERE 'IT' in ( #GroupBy1 )
UNION ALL
SELECT 'Accounts Payable' as Department WHERE 'Accounting' in ( #GroupBy1 )
UNION ALL
SELECT 'Shipping' as Department WHERE 'Warehouse' in ( #GroupBy1 )
UNION ALL
. . .
Create a parameter that uses that data set as available options. (GroupBy2)
Use any combination of these parameters in your core data query or filters.
One restriction is that the parameters must be ordered in the report so that GroupBy1 is before GroupBy2.

Multiple queries as record source for single form?

I'm back with another problem. I have a form based on a query with the parameter in the WHERE clause being the combobox of the form. In the detail, it is continuous form view and shows all the matching fields for the combobox(re-queries after update of combobox). There's a textbox and a button at the footer where the user can add new entries for this data.
I need to have basically a mirror of this form right beside it -- so that they can be compared visually. I need two combo boxes side-by side in my header -- with two controls in the detail section that are populated based on the query. I considered using subform to basically create the illusion of this, but I can't have subforms with continuous form view. The idea that I was thinking was to have two queries as the form's record source:
Select value FROM t1 WHERE criteria = me.combo1;
select value as val2 from t1 WHERE criteria = me.combo2;
Example Data (same structure):
**Friends**
**User friend**
Bob Jack
Bob Zach
Bob Mack
John Juan
John Sha'Quan
I would then have in the detail section a 'value' control and a 'val2' control that would be populated from different queries and criteria.
Is this possible?
Or, should I instead just have two subforms, each with a different parent key determined by the value selected in the combobox? I'd prefer it to be the way I listed, but if there is no other option, is this what I'd have to do?
Try this:
SELECT tx.*, ty.*
FROM (Select id, value FROM t1 WHERE criteria = me.combo1) As tx
LEFT JOIN (select id, value as val2 from t1 WHERE criteria = me.combo2) As ty
ON tx.ID = ty.ID
I had to requery the form in the after update event of the first combo.
SELECT x.*,
y.*
FROM (SELECT t1.user,
t1.friend
FROM t1
WHERE (( ( t1.user ) = [forms]![myForm]![combo5] ))) AS x
INNER JOIN (SELECT user,
friend
FROM t1
WHERE (( ( t1.friend ) = [forms]![myForm]![combo7] ))) AS y
ON ( x.user = y.user )
AND ( x.friend = y.friend );