Note that there are some explanatory texts on larger screens.

plurals
  1. POCombined grouping on two fields
    primarykey
    data
    text
    <p>I have access to just the SELECT and WHERE clause to a database. I have no ability to do any more than fill in the blanks between SELECT and FROM and after WHERE ("SELECT _ _ _ _ _ _ FROM TABLE WHERE _ _ _ _ _")</p> <p>In the database, there are four fields (more in fact, but these are the pertinent ones): "TShirt1", "TShirt1Size", "TShirt2" and "TShirt2Size".</p> <p>TShirt1 and TShirt2 both contain one of "RedCrew", "BlueSlim" or "GreyV"</p> <p>TShirt1Size and TShirt2Size both contain one of "S", "M", "L" or "XL"</p> <p>I want to know if I can create a query that will return the total numbers of each combination. <em>If I didn't have two fields</em>, it would be</p> <pre><code>SELECT TShirt, TShirtSize, count(*) FROM BookingsTable WHERE 1 GROUP BY TShirt, TShirtSize </code></pre> <p>so I would get results like</p> <pre><code>RedCrew, L, 2 BlueSlim, M, 4 </code></pre> <p>etc. </p> <p>Is there any way I can get the same, or similar output, but combining the results of TShirt1 and TShirt2?</p> <p>EDIT: Apologies for the confusion. The actual table would be something like (typed not tested):</p> <pre><code>create table tshirt ( TShirt_id int, TShirt1 varchar(10), TShirt1Size varchar(2), TShirt2 varchar(10), TShirt2Size varchar(2) ); insert into tshirt values (1, 'RedCrew', 'XL', 'BlueSlim', 'M'); insert into tshirt values (2, 'BlueSlim', 'L', 'RedCrew', 'L'); insert into tshirt values (3, 'GreyV', 'L', 'BlueSlim', 'M'); insert into tshirt values (4, 'BlueSlim', 'M', '', ''); insert into tshirt values (5, '', '', 'GreyV', 'L'); insert into tshirt values (6, 'BlueSlim', 'S', 'BlueSlim', 'L'); </code></pre> <p>and the result set I would want (if my math is correct) would be:</p> <pre><code>BlueSlim, S, 1 BlueSlim, M, 4 BlueSlim, L, 2 GreyV, L, 2 RedCrew, L, 1 RedCrew, XL, 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload